Jump to content

Spinning Mesh Wheels by Actual Speed


Icon Allen
 Share

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

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

Recommended Posts

Hello All,

I need just a bit of feedback or knowledge for a small issue I'm having. So I built a motorbike for myself and want the wheels to spin according to the speed of the bike itself not just by a throttle number. The code I'm using to do this is as follows:

 timer()  // this is set to fire every .10 seconds by llSetTimerEvent
    {
        sparkplug++; // this is for other functions that need controlled timing
        poser++;//same as above
        
        vector local_vel = llGetVel() / llGetRot(); 
        if (local_vel.x < 0)
                {
                    reverse = -1;
                }
        if (local_vel.x >= 0)
                {
                    reverse = 1;
                }
        llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_LINK_TARGET,Front_wheel, PRIM_OMEGA,<0.0, (local_vel.x/2)*reverse, 0.0>,TWO_PI,1.0,
                                     PRIM_LINK_TARGET,Back_wheel, PRIM_OMEGA,<0.0, (local_vel.x/2)*reverse, 0.0>,TWO_PI,1.0]);
     }

Now the issue is that sometimes it works perfectly and the wheel will spin exactly to the speed. But other times the wheel just jitters at the same speed as the function is being called. It looks like every time the function is called the wheel rotation is set back to zero. Is there a way to reliably update the wheel rotation speed without calling the function so many times? Is this just the viewer not rendering the spin correctly? Or have I just hit the wall of limitations for the effect I want?

Link to comment
Share on other sites

If you'd rather not keep calling SLPPF so many times, you could trigger it in a control event instead, as

if (CONTROL_FWD & level & ~edge)
{
     llSetLinkPrimitiveParamsFast(LINK_SET,[34,Front_wheel, PRIM_OMEGA,<0.0, (local_vel.x/2)*reverse, 0.0>,TWO_PI,1.0, 34,Back_wheel, PRIM_OMEGA,<0.0, (local_vel.x/2)*reverse, 0.0>,TWO_PI,1.0]);
}

That way, it's only triggered when you hold the forward arrow key (or W) on your keyboard down.

Link to comment
Share on other sites

I was sort of thinking something like that but the issue is then when I let go I have the linear motor set to slowly cruise to a stop. Inside a control event there would be no input during that time to adjust the wheel speed. Also from what I've seen, control events fire off like a raging river, wouldn't that be more intense than what I have in the timer?

Link to comment
Share on other sites

8 minutes ago, Icon Allen said:

Also from what I've seen, control events fire off like a raging river, wouldn't that be more intense than what I have in the timer?

Well, if that's your worry, then use if (CONTROL_FWS & level & edge), so that SLPPF is only triggered when you start holding the forward arrow down.  Then use if(CONTROL_FWD & ~level & edge) to trigger your cool-down routine when you stop holding it down. 

Link to comment
Share on other sites

This is quite do-able. See https://github.com/John-Nagle/l*****ils/blob/master/motorcycle/rotatewheel.lsl

for what I use. That goes in the wheel, and it gets messages to turn it on and off. You don't need to do it that way.

Don't update too often. If the velocity isn't changing much, don't change the omega value.

9 hours ago, Icon Allen said:

Hello All,

I need just a bit of feedback or knowledge for a small issue I'm having. So I built a motorbike for myself and want the wheels to spin according to the speed of the bike itself not just by a throttle number. The code I'm using to do this is as follows:




        llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_LINK_TARGET,Front_wheel, PRIM_OMEGA,<0.0, (local_vel.x/2)*reverse, 0.0>,TWO_PI,1.0,
                                     PRIM_LINK_TARGET,Back_wheel, PRIM_OMEGA,<0.0, (local_vel.x/2)*reverse, 0.0>,TWO_PI,1.0]);
     }

 

PRIM_OMEGA has parameters [ PRIM_OMEGA, vector axis, float spinrate, float gain ]. You have the spin rate inside the axis of rotation, and TWO_PI in the spin rate. The spin rate has to go in the spinrate parameter, and the axis has to be the same as the axis of the wheel.

  • It's useful to skip the updates when the wheel speed isn't changing by much. If the new velocity is within 5-10% of the old velocity, don't bother doing an update. Less jitter.
  • If the spin rate is near 0, set it to exactly 0, so the viewer knows to do a full stop. Very small omega values don't work well.
  • 10 radians/second is a useful limit on rotation speed; above that the frame rate interacts with the rotation rate to cause ugly strobing.

That should get your wheels turning properly.

 

Edited by animats
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1103 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...