I have a 2D game and my goal is to make a car follow a path (the road in the picture) and rotate in the same time. I tried a plugin in the assets store but it didn't work well for me and i had difficulties making work as intended. If you have any suggestions, i ready to listen. Thanks for help in advance.
Thanks everyone for your help. I wanted to say that i achieved the steering behavior of a car by applying what i found in this video(https://www.youtube.com/watch?v=11ofnLOE8pw&t=423s) I edited the scripts furthermore to suit my needs and i added this script which i found also in another video in order to make the car rotate along with the road above(https://www.youtube.com/watch?v=mKLp-2iseDc):
Vector3 targetInVec3 = new Vector3(targetPosition.x, targetPosition.y , 0f); Vector3 direction2 = targetInVec3 - transform.position; float angle = Mathf.Atan2(direction2.y, direction2.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward); transform.rotation = rotation;
Note: the angle variable can be changed to work with the initial rotation of your object. - target is the position of the next point on the curve.
If you have any question feel free to ask me.