import com.nolimitscoaster.*;
import nlvm.math3d.*;
public class attach_object1 extends Script
{
private static final float xOffset = 0; // left/right
private static final float yOffset = 0; //up/down
private static final float zOffset = 0; //back/forth
private static final float range = 5; // The first train within this range of the scene object will receive the attachment. (range is in meters)
private static final int carToAttach = 0; // Defines the car on the train that will receive the attachment. (0 = lead car or zero car)
private SceneObject sco; // Scenery object handle.
private Train train; // Train handle.
private Vector3f posOut = new Vector3f(0,0,0); // Will store the scenery object's position based on the car's position.
private Vector3f pitchHeadBankOut = new Vector3f(0,0,0); // Will store the scenery object's orientation based on the car's orientation.
private Matrix4x4f carMatrix = new Matrix4x4f(); // Will store the car's orientation.
float xOffset_cam1 = 0;
float yOffset_cam1 = 0;
float zOffset_cam1 = 0;
ExternalRideView pov;
public bool onInit()
{
sco = sim.getSceneObjectForEntityId(getParentEntityId());
if (sco == null)
{
System.err.println("BoatTripCar1.nlvm: This script must be assigned to a scene object.");
return false;
}
TrackPos trackPos = sim.findNearestCoasterTrack(sco.getTranslation(), range);
if (trackPos == null)
{
System.err.println("BoatTripCar1.nlvm: No track found within range of " + range + " meters.");
return false;
}
Coaster coaster = trackPos.getCoaster();
train = coaster.findNearestTrain(sco.getTranslation(), range);
if (train == null)
{
System.err.println("BoatTripCar1.nlvm: No train found within range of " + range + " meters.");
return false;
}
pov = sim.createExternalRideView();
pov.setEnterWarpPointEnabled(true);
pov.setLabel("Enter POV Cam");
return true;
}
Matrix4x4f matrixCamera = new Matrix4x4f();
public void onNextFrame(float tick)
{
train.getCarMatrix(carToAttach, carMatrix);
Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
Matrix4x4f matrix = new Matrix4x4f();
matrix.initTrans(xOffset, yOffset, zOffset);
carMatrix.multRight(matrix);
Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
sco.setRotation(pitchHeadBankOut);
sco.setTranslation(posOut);
Matrix4x4f matrixCamera = new Matrix4x4f();
matrixCamera.initTrans(xOffset_cam1, yOffset_cam1, zOffset_cam1);
carMatrix.multRight(matrixCamera);
pov.setEnterWarpPoint(posOut,(float)10);
pov.setCameraMatrix(carMatrix);
}
}
float xOffset_cam1 = 0.0f; // left /right
float yOffset_cam1 = 0.0f; // up / down
float zOffset_cam1 = 0.0f; // back / forth
Return to NoLimits Coaster 2 Scripting