Jump to content

Wheels of the car rotate in "eights"


Metacortex
 Share

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

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

Recommended Posts

Hey! I'm trying to make a single-script car engine, and this is how the rotation of the wheels looks like:

            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, < fwd * (throttle * 0.01), 0, 0 > );
            llSetLinkPrimitiveParamsFast(WHEEL, [PRIM_OMEGA, AXIS, throttle * 0.2, 1
        , PRIM_LINK_TARGET, WHEEL_2, PRIM_OMEGA, AXIS, throttle * 0.2, 1
        , PRIM_LINK_TARGET, WHEEL_3, PRIM_OMEGA, AXIS, throttle * 0.2, 1
        , PRIM_LINK_TARGET, WHEEL_4, PRIM_OMEGA, AXIS, throttle * 0.2, 1]);

and this is how the front wheels turn left/right:

    llSetLinkPrimitiveParamsFast(
    WHEEL_L, [PRIM_ROT_LOCAL, llEuler2Rot(<0,0,30*dir> * DEG_TO_RAD),
    PRIM_LINK_TARGET, WHEEL_R, PRIM_ROT_LOCAL, llEuler2Rot(<0,0,30*dir> * DEG_TO_RAD)]);

But then a problem arises - when turning the car - the front wheels begin to move in "eights"! How to fix it?

Edited by Metacortex
Link to comment
Share on other sites

By "eights" I mean that the normal y-axis rotation of the wheels intersects with the z-axis turns. It actually looks pretty funny, as if car's axis is bent.

 

In other words, how to rotate a y-rotated object along the z-axis without intersection?

Link to comment
Share on other sites

  • Metacortex changed the title to Wheels of the car rotate in "eights"

To get the wheels turning true while on the steering angle you need to also update the axis of the PRIM_OMEGA otherwise it will continue to go around on the previously defined axis. So like the axis you already have is the axle for going in a straight line, you also need to define axis vector values for the axle when turned left or right.

Most car wheels using the omega method to go around do tend to 'wobble' at least a little bit when the steering begins/ends, as the rotation and omega updates rarely actually happen in the same moment.

The alternative for zero-wobble wheels is a fairly involved set of quaternion rotation mathematics, which is why hardly anyone does it  :) 

  • Like 1
Link to comment
Share on other sites

Assuming the Y-axis points through the hub of the wheel:

float Z = 1.5;//** how far left or right the wheel is currently turned (In Radians) **
float Y = 1.5; //** how far the wheel currently is in its turning cycle **

rotation rot_wheel = llAxisAngle2Rot(<0,1,0>,Y)*llAxisAngle2Rot(<0,0,1>,Z);
// set all the wheels to that rotation with LLSLPPF.

It's not quaternions that are hard, but rotations themselves are not very intuitive until you have a good sit down and think about them.

  • Thanks 1
Link to comment
Share on other sites

12 hours ago, Quistess Alpha said:

Assuming the Y-axis points through the hub of the wheel:

float Z = 1.5;//** how far left or right the wheel is currently turned (In Radians) **
float Y = 1.5; //** how far the wheel currently is in its turning cycle **

rotation rot_wheel = llAxisAngle2Rot(<0,1,0>,Y)*llAxisAngle2Rot(<0,0,1>,Z);
// set all the wheels to that rotation with LLSLPPF.

It's not quaternions that are hard, but rotations themselves are not very intuitive until you have a good sit down and think about them.

Thanks a lot for the kindly provided example! Please tell me what am I doing wrong? For some reason the wheels are not steering yet.

I set this up as global variables

float Z = 1.5;//** how far left or right the wheel is currently turned (In Radians) **
float Y = 1.5; //** how far the wheel currently is in its turning cycle **

here is my wheel turning function

setWheel(integer dir)
{
    rotation rot_wheel = llAxisAngle2Rot(<0,1,0>,Y)*llAxisAngle2Rot(<0,0,1>,Z); // set all the wheels to that rotation with LLSLPPF.
      
    llSetLinkPrimitiveParamsFast(
    WHEEL_FRONT_L, [PRIM_ROT_LOCAL, rot_wheel,
    PRIM_LINK_TARGET, WHEEL_FRONT_R, PRIM_ROT_LOCAL, rot_wheel]);
}

and then in the control event I set it like this

control(key name, integer level, integer edge)
{
    ...

    if (level & CONTROL_ROT_LEFT)
    {
        setWheel(-1);
    }
    if (level & CONTROL_ROT_RIGHT)
    {
        setWheel(1);
    }
    if (level & CONTROL_LEFT)
    {
        setWheel(-1);
    }
    if (level & CONTROL_RIGHT)
    {
        setWheel(1);
    }
    ...
}

 

Edited by Metacortex
Link to comment
Share on other sites

2 hours ago, Metacortex said:

Please tell me what am I doing wrong

you're not doing anything meaningful with the Dir variable, and you're not setting X and Y. This isn't the sort of thing you just plug into your script and expect it to work, you need to actually think through what you're doing. Also, if your wheels aren't mesh, or are UV-mapped in a clever enough way, I'd suggest just using texture animation for the roll as Animats suggested. Otherwise, you're going to need a tight timer in addition to your control event, which does something to the effect of

timer()
{  float step = llGetAndResetTime();
   Y+=step*SPIN_SPEED;
   Z+=step*TURN_SPEED*TURN_DIRECTION;
   if(Z<TURN_MIN)
   {  Z=TURN_MIN;
   }else if(z>TURN_MAX)
   {  Z=TURN_MAX;
   }
}

filling in with global variables or constants.

Link to comment
Share on other sites

22 minutes ago, Metacortex said:

it doesn’t matter, just another failed experiment, I’m already used to it. 

If you give up after every set-back, you're not going to get very far. This is entirely doable if you put your mind to it.

  • Like 1
Link to comment
Share on other sites

28 minutes ago, Quistess Alpha said:

If you give up after every set-back, you're not going to get very far. This is entirely doable if you put your mind to it.

Which is simple for one, difficult for another. I never studied scripting specifically, except Basic in elementary school.

After so many failures, like mine, you begin to feel good about the insuperability of the task and rather quickly your interest in struggling disappears.

However thanks for trying to help! :)

 

Link to comment
Share on other sites

On 1/6/2022 at 4:52 PM, Metacortex said:

How to fix it?

As has been mentioned, you need to update the omega spin axis as well when the wheels turn. The downside is still that the wheels will start spinning from zero, which makes them snap back everytime you turn the wheels. That's why I used only texture animations on turning wheels so far. That has it's own set of limitations though.

llSetLinkPrimitiveParamsFast(WHEEL, [PRIM_OMEGA, AXIS * llEuler2Rot(<0,0,30*dir> * DEG_TO_RAD), throttle * 0.2, 1
        
Edited by arton Rotaru
Link to comment
Share on other sites

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