Jump to content

yet another ferris wheel


Xed Saunders
 Share

You are about to reply to a thread that has been inactive for 1497 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

hi all, i'm builting a simple ferris wheel from the scratch, i've built two scripts, one for the wheel itself and one for the cars.

this is the root (wheel) script

rotation rot_xyzq;
integer on;
 
rotate()
    {
        llSetRot(llGetRot()*rot_xyzq); //Do the Rotation...        
    } 
    
default
{
    state_entry()
    {
        vector xyz_angles = <0,-1.0,0>; // This is to define a 1 degree change
        vector angles_in_radians = xyz_angles*DEG_TO_RAD; // Change to Radians
        rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
        llListen(-65538,"","","");
    }
    
    listen(integer channel, string name, key id, string message)
    {
    if (message=="start") {    
    on = !on;        
    if (on)
        {
        llSetTimerEvent(0.05);        
        }
    else
        {
        llSetTimerEvent(0.0);
        llRegionSay(6000,"reset");    
        }    
    }
    }   
    timer()
    {
     rotate();
     llRegionSay(6000,"click");   
    }
        
}

and this is the car script

rotation rot_xyzq;
rotate()
    {
    llSetRot(llGetRot()*rot_xyzq/llGetRootRotation()/llGetRootRotation()); //Do the Rotation...
    }
     
default
{
    state_entry()
    {
        vector xyz_angles = <0,1.0,0>; // This is to define a 1 degree change
        vector angles_in_radians = xyz_angles*DEG_TO_RAD; // Change to Radians
        rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
        llListen(6000, "", "", "");
    }
 
    listen(integer channel, string name, key id, string message)
    {
    if (message=="click")
        {
            rotate();
        }    
    }
}

the wheel move stuttering a bit but works, i've avoided to use the lltargetomega even if much smoother because that is a viewer thing and when i tried it i've i got much troubles than joy.

i have set 8 wagons around the root each one containing the child script,each wagon is a single mesh prim

the questions i have are two, beside the scripts itself that can be enhanced, the wheel rotate off center, i have a cylindrical prim which is my root and when i start the scripts the cars rotate around it using a different path, i have to de-center the root to have the wagons rotate around the wheel. how to fix this?

then the biggest problem, being a ferris wheel i must provide seats, i tried to add a prim in the car to let someone sit but even if the prim is linked to the car the sit animation rotate with the wheel :(

i tried to add avsitter2 both straight in the car or using a separate prim but results are the same. the sitter rotate and when the wagon is on the top of the wheel it is upside down.

look like i have to use another approach, in design or there is a solution to fix the seat with the rotation?

thanks in advance

 

 

Link to comment
Share on other sites

Regarding stuttering:

Just because you set a timer event for every 0.05 seconds doesn't mean that's when the timer will run.

Better to calculate the elapsed time each timer event by using llGetTime() and llResetTime() and calculate the true rotation needed based on that. It will look smoother and correct for timer inconsistency. You could set timer event to 1/llGetRegionFps() to ensure that each simulation frame of the simulator the rotation is calculated making it as smooth as can be. 

Regarding seats in car:

I would discourage having a separate script in each car as it introduces latency between the movements and requires parsing strings which is not optimal.

I recommend instead using llSetLinkPrimitiveParamsFast from the root prim in conjunction with PRIM_ROTATION, to control each car link during every timer event to correct for the rotation of the main wheel.

 

Edited by Extrude Ragu
Add information regarding seperate scripts
  • Like 1
Link to comment
Share on other sites

I am bored stuck at home so I had a go at implementing this.

Preview

https://i.gyazo.com/9d0168650a2a83607996148573c18561.mp4

Script

https://pastebin.com/p00LMaat

Note that my script assumes that all cars are any non-root link prims, you might have to manually populate the list if that's not the case.

Edited by Extrude Ragu
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

so I built one... and sat my avatar on one of the cars...

and she is turning around while the car stays in the upright position

oops - where did i go wrong?

Emma :) 

... tried again just now... this time, she is going around the car prim in the right position but making a 2m or so circle around the car prim... hmm

 

Snapshot_001.png

Edited by Emma Krokus
Link to comment
Share on other sites

thanks for the great script Extrude, i'll try to use my skill to build at least nice cars and wheel meshes :D

regarding Emma question, yes that is the same i'm experiencing, the sitter position rotate so maybe the seat position must be adjusted as the car spins.

Link to comment
Share on other sites

This turns out to be deeply complicated.

From what I've read, agents that sit on an object are not attached to the child prim they sit on, but rather the object as a whole.

That means that the agent is actually being treated as a separate link and is rotating around the root like a child prim would. In order for the agent to appear to remain on the object, the agent would not only need to be rotated like the child prim, but would also need to be moved so that it's position offset relative to the child prim is rotated around the child prims axis (Oh mama..)

I'd guess you would need to hook the changed event to detect when agent(s) sit on the object, and figure out which prim they're supposed to be sat on. This'll be whatever child prim is closest, which could be figured out by using llVecDist against agent local position/all child prims local position (PRIM_POS_LOCAL) to figure out which is nearest. You'd then save the inferred child prim, the rotation of the child prim at the time the agent sat on it, the agent offset relative to that prim,  the agents intial rotation, and the link number of the agent (Phew..)

Then, each simulator frame (timer event) you'd take the child prim's rotation, subtract the child prims initial rotation to get the change in rotation of the child prim. You'd then rotate the agents initial offset around that axis to get the new local position the agent should be in, and you would also rotate the agent based on the agents initial rotation and the change the same way the child prims are rotated.

I am going to leave that as an exercise to the reader because I have other stuff to do, but I have in the past written a script function to rotate a position vector around an axis which is probably useful for this scenario:-

vector rotate_around_axis(vector axis, vector position, rotation r)
{
    // Calculate position's offset from axis.
    vector offset = position - axis;
    // Rotate the offset
    vector rotOffset = offset * r;
    return axis + rotOffset;
}

Hope it helps :)

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1497 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...