Skip to content

All Comments

11761 to 11780 of 19729

Filter comments

Terra, Phase 4
NoLimits Coaster

You can use multiple scripts per object, so you could use a seperate script to handle the animations if you wanted to do it that way. Looks like Train.getHarnessState() is the function you want. So presumably you'll keep checking the value then begin the animations when it switches.

Here's a script I made that might help with the keyframe animation. I made it for a rolling station, so It currently uses track triggers to start the animation


public class WaterboatRestraints extends Script implements TrackTriggerListener
{
        private Coaster c;
        private Train t;
        private SceneObject sco;

        private bool animation_enabled = false;
        private double animation_start;
        private double animation_end;
        private double animation_current = 2.0;

        private long time_current = 0;
        private long time_last;

        private TrackTrigger triggerOpen, triggerClose;


    public void onTrainEntering(TrackTrigger trigger, Train train)
    {
        if(train != t)
            return;

        if(trigger == triggerOpen && animation_current != 2.0)
        {
            animation_enabled = true;
            animation_start = 0.0;
            animation_end = 2.0;
            animation_current = 0.0;
        }
        else if (trigger == triggerClose && animation_current != 0.0)
        {
            animation_enabled = true;
            animation_start = 2.0;
            animation_end = 4.0;
            animation_current = 2.0;
        }
    }


    public void onTrainLeaving(TrackTrigger trigger, Train train)
    {
            return;
    }


    public void onNextFrame(float tick)
    {
        // Update timer count
        time_last = time_current;
        time_current = System.currentTimeMillis();
        double time_diff = (double)(time_current - time_last) / 1000;

        if (animation_enabled != true)
            return;

        // Play current animation
        animation_current += time_diff;
        sco.setKeyFrameAnimationTime(animation_current);

        if (animation_current >= animation_end)
        {
            animation_enabled = false;
            animation_current = animation_end;
        }
    }


    public bool onInit()
    {
        //load the attachment object
        sco = sim.getSceneObjectForEntityId(getParentEntityId());
        sco.setKeyFrameAnimationTime(animation_current); //start open
        c = sim.getCoasterAt(0);

        //Find the nearest Coaster
        TrackPos trackPos = sim.findNearestCoasterTrack(sco.getTranslation(), 5);
		if (trackPos == null)
		{
			System.err.println("WaterboatRestraints: No track found within 5 meters.");
			return false;
		}
		else
		{
			c = trackPos.getCoaster();
        }

        //Find the nearest train
        t = c.findNearestTrain(sco.getTranslation(), 5);

        // Add Trigger Listeners
        triggerOpen = c.getTrackTrigger("restraint_open");
        triggerClose = c.getTrackTrigger("restraint_close");
        triggerOpen.addTrackTriggerListener(this);
        triggerClose.addTrackTriggerListener(this);

        return true;
    }
}
View comment
Terra, Phase 4
NoLimits Coaster

Are the dummy restraints connected to the hidden restraints?

Because you could use bestdanis restraint script which takes a animation that you keyframe in blender and makes it move when the restraint moves

View comment
Terra, Phase 4
NoLimits Coaster

Okay, so if I animate the doors, what exactly would I need to add to the script for it to activate when the dummy train restraints open/close?

This is the script I'm using here:

import com.nolimitscoaster.*;
import nlvm.math3d.*;


public class Monorail1 extends Script
{
    private static final float xOffset = 0; // left/right
    private static final float yOffset = 1.5f; //up/down
    private static final float zOffset =  0.0f; //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 static final int trainToAttach = 1;
    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 = -2;
    // float yOffset_cam1 = 0.0f;
    // float zOffset_cam1 = 0.0f;
    
    private static final float warpRange = 4;
    private static final int numSeats = 12;
    ExternalRideView pov;
    
    public bool onInit()
    {                                   
        sco = sim.getSceneObjectForEntityId(getParentEntityId());
        if (sco == null)
        {
            System.err.println("Monorail1.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("Monorail1.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("RaftingCar.nlvm: No train found within range of " + range + " meters.");
            return false;
        }
        
        pov = sim.createExternalRideView();
      pov.setEnterWarpPoint(sco.getTranslation(), warpRange);
      pov.setEnterWarpPointEnabled(true);
      pov.setLabel("Enter Skytrain Front Cab");
        
        return true;
    }

    Matrix4x4f matrixCamera = new Matrix4x4f();
    
    public void onNextFrame(float tick)
    {
        pov.setEnterWarpPoint(sco.getTranslation(), warpRange);
        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);
    
        if (pov.isActive())
        {
            int curCar = pov.getCurrentSeatIndex(numSeats);
            Matrix4x4f m = sco.getAbsoluteMatrix();

            Matrix4x4f m2 = new Matrix4x4f();
      
            m2.initTrans(0.0f, 0.0f, -4.0f);  //(up-down,.../left-right/,.../back-forth)
            m.multRight(m2);
     
            m2.initZRot(-(float)Math.PI *0.0f);      
            m.multRight(m2);
      
            float fSeatRot = (float)(Math.PI * 2 / (float)numSeats);
            m2.initYRot(fSeatRot);
            m.multRight(m2);

            pov.setCameraMatrix(m);
        }
    }
}
View comment
11761 to 11780 of 19729