Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wheel control at the car
#1
Hi, i have a machine that moves along the path as in this video. (Without physics)



Is it possible to synchronize the rotation of the wheels and their turn? (Depending on the speed and steepness of the curve)


Any help would be appreciated.
Reply
#2
Hi,

Can you please explain me the logic of movement of the car? I see that it goes left and right of the path. Is it through user inputs?

If the car followed strictly the path, I would have suggested you to align the wheels with the spline's tangent. It might give a good result.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
The machine moves strictly on the spline. I managed to achieve the rotation of the wheels. It remains to realize the turn of the front wheels. Here's my video:



Can you tell me a sample code how to get a tangent to apply to turning the wheel?
Reply
#4
Off the top of my head:

Vector3 frontWheelLocalPosition = XXX; // The position in the spline's local space.
float frontWheelTf = spline.GetNearestPointTF(frontWheelLocalPosition );
Vector3 tangent = spline.GetTangent(frontWheelTf);

More info about how to use these methods is available in the method's documentation
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Thanks for help!

Wrote this script to get tangent.
Code:
       Vector3 wheelLocalPos = splinePos.InverseTransformPoint(wheelFrontR.transform.position); 
       float frontWheelTf = spline.GetNearestPointTF(wheelLocalPos);
       tang = spline.GetTangent(frontWheelTf);
       wheelFrontR.transform.localEulerAngles = new Vector3(0.0f, tang.z * 30, 0.0f); // turning the wheel

Result



But the result was quite strange. 
I think I'm getting the angle wrong. Help please, where is my mistake?
Reply
#6
In general, spline's data is expressed in spline's space, and you will need to convert them to global space when needed. So the tangent you get needs to be converted back to global space.

Then do this:
wheelFrontR.rotation = Quaternion.LookRotation(tangentInGlobalSpace, yourCarUp);
You might need to do an additional 90° rotation around the up vector, depending on the orientation of your mesh.

In general, when things go wrong, I advise you to debug things step by step, and visually. Use the Debug.DrawLine and similar methods to check the result at each significant step of your code, and I am sure you will rapidly find at which step things went wrong.

If after all this, you still can't manage to make the wheels align with the tangent, please send me a mini-project with everything setup, and I will take a look at it.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
Thank you! It worked! I used tangent incorrectly.
Final code (can someone use to anyone)


Code:
       Vector3 wheelLocalPos = splinePos.InverseTransformPoint(wheelFrontR.transform.position);
       float frontWheelTf = spline.GetNearestPointTF(wheelLocalPos);
       tang = spline.GetTangent(frontWheelTf);

       wheelFrontR.transform.rotation = Quaternion.LookRotation(tang, new Vector3(0, 1, 0)); // turn wheel
Reply
#8
Thanks for sharing
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#9
(10-30-2018, 10:15 AM)xcube Wrote: Thank you! It worked! I used tangent incorrectly.
Final code (can someone use to anyone)


Code:
       Vector3 wheelLocalPos = splinePos.InverseTransformPoint(wheelFrontR.transform.position);
       float frontWheelTf = spline.GetNearestPointTF(wheelLocalPos);
       tang = spline.GetTangent(frontWheelTf);

       wheelFrontR.transform.rotation = Quaternion.LookRotation(tang, new Vector3(0, 1, 0)); // turn wheel

Yes it really works ..
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Move between control points Livealot 2 332 08-02-2018, 07:33 PM
Last Post: Livealot
  Add control point along spline hoesterey 3 1,417 03-20-2018, 04:20 PM
Last Post: nomadigi
  Detecting if I'm in a "Connection" control point atomsinthevoid 1 748 01-28-2018, 12:21 AM
Last Post: _Aka_
  Connecting only last and first Control Point RealXaon 1 709 01-17-2018, 10:37 PM
Last Post: _Aka_

Forum Jump: