I want when I press A or D the car moves and some rotations for suspension effect like Traffic Racer.I tried this code but its not looking smooth.What should I do?
private float curveAmount = 50.0f;
private float rotateSpeed = 100.0f;
if (Input.GetKeyDown("a"))
{
this.transform.rotation = Quaternion.RotateTowards(this.transform.rotation, Quaternion.Euler(20f, 0.0f, -curveAmount), rotateSpeed * Time.deltaTime);
}
if (Input.GetKeyDown("d"))
{
this.transform.rotation = Quaternion.RotateTowards(this.transform.rotation, Quaternion.Euler(20f, 0.0f, -curveAmount), rotateSpeed * Time.deltaTime);
}
The WheelCollider object supports suspension directly.
Otherwise you’re pretty much reinventing your own physics.
For smoothness, you need to change the angle(s) over time, not all at once in one statement.
Smoothing movement between discrete values:
The problem is the choice of integer values for lanes. They can only either be lane 0, 1 or 2. They can’t be in between round numbers. It needs to be a floating point value so that it can be between lanes.
This type of question comes up so universally I have finally just made a sample package to demonstrate the basic concept. Read my first post above and see if you can correlate each part of the code to the steps indicated.
Code located here: SmoothMovement.cs · GitHub
6430100–719246–SmoothMo…
The code: Smooth movement - Pastebin.com
I dont want use Wheel Collider because my road is straight.I just need lane changing not car rotation that is why I only need effects.I hope I could explain and I am beginner.Do you have any advice to me about it?
Definitely start with any one of the over 200,000 tutorial videos. No need for someone here to type it all back in!!