Search Unity

  1. Click here to receive a gift with your purchase of Unity Pro or Unity Enterprise.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

wheels rotating wrong

Discussion in 'Scripting' started by slashdotray, Sep 21, 2007.

  1. slashdotray

    slashdotray

    Joined:
    Dec 3, 2006
    Posts:
    77
    just moved to a new topic...

    hi again...
    i just tried out this great vehhicleexample with tank and boat and jeep, and now i saw that the graphical wheels are turning false.
    if i drive backwards the wheels are turning forward.

    i coudnt get it fixed....still kind of newbie

    thanks to everybody who can help me
    Confused


    so the snippet which do the rotation in my eyes ist:


    here is the function which updates the wheels


    //rotate wheel
    w.rotation += wheelRPM / 60.0 * 360.0* Time.fixedDeltaTime;
    w.rotation = Mathf.Repeat(w.rotation, 360.0);
    w.graphic.localRotation= Quaternion.Euler( w.rotation, w.maxSteerAngle*steer, 0.0 ) * w.originalRotation;

    i think somwhere around here it is ?!
     
  2. bronxbomber92

    bronxbomber92

    Joined:
    Nov 11, 2006
    Posts:
    890
    Well, if the rotation around the x-axis is opposite, then just negate the x angle.

    Code (csharp):
    1. w.graphic.localRotation= Quaternion.Euler( -w.rotation, w.maxSteerAngle*steer, 0.0 ) * w.originalRotation;
     
  3. slashdotray

    slashdotray

    Joined:
    Dec 3, 2006
    Posts:
    77
    thanks very much, i will try this out.
     
  4. azabug

    azabug

    Joined:
    Aug 8, 2007
    Posts:
    111
    Are you sure the Rotation is wrong?
    If it is you can create the opposite motion as bronxbomber92 mentioned ...

    I just had a thought though .... if the wheels are moving fast enough it can create an optical illusion ... you know when you watch a bicycle wheel spinning there is a point when the wheel appears to spin in the opposite direction ... I've noticed this effect in some of my projects.

    Cheers
     
  5. slashdotray

    slashdotray

    Joined:
    Dec 3, 2006
    Posts:
    77
    thanks,

    i checked it, but the wheels are doing wrong.
    if you look into the vehicles_example:

    //update wheel status
    function UpdateWheels()
    {
    //calculate handbrake slip for traction gfx
    handbrakeSlip=handbrake*rigidbody.velocity.magnitude*0.1;
    if(handbrakeSlip>1)
    handbrakeSlip=1;

    totalSlip=0.0;
    onGround=false;
    for(w in wheels)
    {
    //rotate wheel
    w.rotation += wheelRPM / 60.0 * 360.0* Time.fixedDeltaTime;
    w.rotation = Mathf.Repeat(w.rotation, 360.0);
    w.graphic.localRotation= Quaternion.Euler( w.rotation, w.maxSteerAngle*steer, 0.0 ) * w.originalRotation;

    //check if wheel is on ground
    if(w.coll.isGrounded)
    onGround=true;

    slip = cornerSlip+(w.powered?driveSlip:0.0)+(w.handbraked?handbrakeSlip:0.0);
    totalSlip += slip;

    var hit : WheelHit;
    var c : WheelCollider;
    c = w.coll;
    if(c.GetGroundHit(hit))
    {
    //if the wheel touches the ground, adjust graphical wheel position to reflect springs
    w.graphic.localPosition.y-=Vector3.Dot(w.graphic.position-hit.point,transform.up)-w.coll.radius;

    //create dust on ground if appropiate
    if(slip>0.5 hit.collider.tag=="Dusty")
    {
    groundDustEffect.position=hit.point;
    groundDustEffect.particleEmitter.worldVelocity=rigidbody.velocity*0.5;
    groundDustEffect.particleEmitter.minEmission=(slip-0.5)*3;
    groundDustEffect.particleEmitter.maxEmission=(slip-0.5)*3;
    groundDustEffect.particleEmitter.Emit();
    }

    //and skid marks
    if(slip>0.75 skidmarks != null)
    w.lastSkidMark=skidmarks.AddSkidMark(hit.point,hit.normal,(slip-0.75)*2,w.lastSkidMark);
    else
    w.lastSkidMark=-1;
    }
    else w.lastSkidMark=-1;
    }
    totalSlip/=wheels.length;
    }


    i do not know how to seperate the forward backward drive.
     
unityunity