Jump to content

Rotation simulating car wheel


prootoxy
 Share

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

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

Recommended Posts

Hello friends how are you???
I've been stuck for hours on a problem and I would like to know if someone could help me...
I need to create a car wheel, this wheel needs to rotate and turn left or right while rotating. But when I do both things together (Rotate the wheel and turn it to one side) it doesn't stay on a correct axis. I've spent hours reading the documentation, trying to understand and I really couldn't, I'd like to know if it's possible for someone to help me with this, I'll leave some examples below.

How i would like to simulate:

ezgif-5-28d4ced49c.gif

 

 

 

How it looks normally when I don't turn it to one side, but I turn it normally at a 90 degree angle to the Z axis:

ezgif-5-5d6d4c0e31.gif

 

 

 

How it looks when I rotate it at a 70 degree angle on the Z axis (to simulate turning right)ezgif-5-494096a626.gif

 

Link to comment
Share on other sites

A) all of your images are 404- not found.

B) Doing anything with rotations is very dependent on the specific 'intrinsic orientation' of your wheels and the main body of the thing they're attached to. snipping the relevant portion from the last time I did this (this was added to someone else's code so the variable names are a bit different than my usual style) :

// Wheel link numbers
integer leftfrontwheel = 11;
integer rightfrontwheel = 4;
integer leftbackwheel = 15;
integer rightbackwheel = 14;

// Wheel axis
vector wheelaxis = <1,0,0>; // for rotating 
vector wheelup = <0,0,1>; // for turning left/right
rotation wheelBaseRot = <0,0,0.71,0.71>; // initial rotation of the wheel.

// Wheel  current status
float turnAngle = 0.0; // radians;
float forwardAngle = 0.0; // radians;

// Wheel spin speed
float spinspeedback = -0.025;
float spinspeedforward = 0.05;

float turnSpeed = 0.02;

float turnAngleMax = 0.45; // maximum angle left or right.

turnWheels(float lr, integer forward)
{   if(turnAngle<lr) turnAngle += turnSpeed;
    if(turnAngle>lr) turnAngle -= turnSpeed;
    if(forward==1)
    {   forwardAngle += spinspeedforward; 
        if(forwardAngle>TWO_PI) forwardAngle-=TWO_PI;
    }else if(forward==-1)
    {   forwardAngle += spinspeedback;
        if(forwardAngle<0) forwardAngle+=TWO_PI;
    }
    llSetLinkPrimitiveParamsFast(
                              leftfrontwheel,[PRIM_ROT_LOCAL, 
                llAxisAngle2Rot(wheelaxis,forwardAngle)*llAxisAngle2Rot(wheelup,turnAngle)*wheelBaseRot,
            PRIM_LINK_TARGET, rightfrontwheel,PRIM_ROT_LOCAL,
                llAxisAngle2Rot(wheelaxis,forwardAngle)*llAxisAngle2Rot(wheelup,turnAngle)*wheelBaseRot,
            PRIM_LINK_TARGET, leftbackwheel,  PRIM_ROT_LOCAL,
                llAxisAngle2Rot(wheelaxis,forwardAngle)*llAxisAngle2Rot(wheelup,-turnAngle)*wheelBaseRot,
            PRIM_LINK_TARGET, rightbackwheel, PRIM_ROT_LOCAL,
                llAxisAngle2Rot(wheelaxis,forwardAngle)*llAxisAngle2Rot(wheelup,-turnAngle)*wheelBaseRot]);
    
}

That's a lot of boiler-plate; the basic idea is you need to keep track of 3 rotation variables: 1) the rotation when the wheel is in its initial 'default' position 2) the rotation that makes the wheel roll forward (or backwards) 3)  the rotation that makes the wheel turn left and right. you then set the PRIM_ROT_LOCAL of the wheel to 2) * 3) * 1) .

That was for a specific mesh wheel; for a standard prim cylinder the relevant parameters are:

vector wheelaxis = <0,0,1>; // for rotating 
vector wheelup = <1,0,0>; // for turning left/right
rotation wheelBaseRot = //<0.0,0.71,0.0,0.71>; // y-forward.
    <-0.5,0.5,0.5,0.5>; // x-forward.

 

Edited by Quistess Alpha
  • Thanks 1
Link to comment
Share on other sites

Bigger idea is that to set the orientation of an object in-world, one of the most useful paradigms to keep in mind is that orientation*change causes a change based on global axes, but change*orientation causes a change based on local axes. Consider:

rotation r;
default
{   state_entry()
    {   r = llAxisAngle2Rot(<0,0,1>,15*DEG_TO_RAD); // 15 degree rotation about z axis.
        llSetRot(<llFrand(1.0),llFrand(1.0),llFrand(1.0),llFrand(1.0)>); // randomize orientation.
    }
    touch_start(integer total_number)
    {   // use one of the following:
        llSetRot(llGetRot()*r); // global rotation
        //llSetRot(r*llGetRot()); // local rotation
    }
}
  • Thanks 1
Link to comment
Share on other sites

14 minutes ago, animats said:

Wheels should be spun with llTargetOmega. Then the viewer does the work. If you spin wheels by setting the rotation, it takes many extra object updates and motion will not be as smooth.

Possibly useful code: https://github.com/John-Nagle/l*****ils/blob/master/motorcycle/rotatewheel.lsl

I had to click on the link to learn, "LSL Utils" is redacted!

  • Like 2
  • Haha 2
Link to comment
Share on other sites

11 hours ago, animats said:

If you spin wheels by setting the rotation, it takes many extra object updates and motion will not be as smooth.

True, but Omega for rolling might behave oddly when combined with left and right 'turning' which requires directly setting the rotation in any case. I might give it a test next I get in-world though.

ETA: Making Omega and turning work together is non-trivial. The main issues to grapple with are that Omega's axis parameter is in the coordinate space of the root prim; setting the rotation while omega is active continues to rotate in object-local coordinates which leads to wobble; setting both the rotation and omega at the same time can lead to the spin of the wheel jumping back to zero (the wheel 'stops spinning' while it's turning left or right)

All of those issues are manageable, but not easy to work around if you don't have a decent understanding of rotations.

see:

 

Edited by Quistess Alpha
Link to comment
Share on other sites

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