Car Controls without physics.
I need to Controls to my car with out rigid body. simply using trasform.traslate and rotate. here is what i did.
accelarationInput = Input.GetAxis ("Vertical");
SteerAngle = Input.GetAxis ("Horizontal");
transform.Translate (0, 0, Speed * Time.deltaTime);
transform.RotateAroundLocal (Vector3.up, SteerAngle Speed 0.03f * Time.deltaTime);
but it is not giving realistic motion it is simple traslating and the rotation also bad.
Answer by goutham12 · Nov 08, 2017 at 02:44 PM
public float accelarationInput;
public float SteerAngle;
public float gravity;
public float Speed;
public GameObject Pivot;
void Update () {
UpdateAccelaration ();
UpdateSteerAngle ();
}
void UpdateAccelaration()
{
if (Application.platform == RuntimePlatform.WindowsEditor) {
accelarationInput = Input.GetAxis ("Vertical");
}
if (accelarationInput > 0) {
Speed += Time.deltaTime * 40;
if (Speed > 100) {
Speed = 100;
}
} else if (accelarationInput == 0) {
if (Speed > 0) {
Speed -= Time.deltaTime * 25;
if (Speed < 0)
Speed = 0;
}if (Speed < 0) {
Speed += Time.deltaTime * 25;
if (Speed > 0)
Speed = 0;
}
} else {
Speed -= Time.deltaTime * 25;
if (Speed < -60)
Speed = -60;
}
transform.Translate (0, 0, Speed* Time.deltaTime);
}
void UpdateSteerAngle()
{
if (Application.platform == RuntimePlatform.WindowsEditor) {
SteerAngle = Input.GetAxis ("Horizontal");
} else {
SteerAngle = simpleJoystick.instance.H / simpleJoystick.instance.Radius;
}
transform.RotateAround(Pivot.transform.position,transform.up,SteerAngle * Speed/2 * Time.deltaTime);
}
it works great. if you don't want to use physics in your car this is the best start up.
Your answer
Follow this Question
Related Questions
How to translate an object in an unknown angle ? 1 Answer
transform.Translate() effect is being reverted 0 Answers
How do I change the position of my player model after I rotate it so it's not teleporting? 0 Answers
How to transform a GameObject to an Empty GameObject's position and rotation 1 Answer
Why does my weapon rotation change after hitting play? 0 Answers