I’m new to Unity but worked a programmer for many years, mostly on the backend-side of game development, frontend and 3d programming is kind of new for me.
I’m building a hoverracer, however the rotation dynamics in Unity confuses me alot.
At this state I’m only applying torque based on the Horizontal input axis on my craft.
But there is other factors I want the hovercraft to rotate to:
- Tilt: I want to tilt the craft when i steer it.
- The ground: Since i use a ray to measure the hovercraft distance to the ground (to be able to add a scaleble downforce to get the craft hover) i can get the normal from the ground. How do i apply it’s rotation (without loosing the steering) to the craft.
- I want the craft to slowly always level out, for instance when it jumps i want the craft level out to it’s “normal” state.
I really have no clue howto apply all this rotation on a object. Everything i try just breaks my steering.
Here is a snippet from my craft-skript (C#):
/*
* Turn
*/
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
transform.Rotate(0, rotation, 0);
rigidbody.AddTorque(0,rotation,0);
/*
* Forward
*/
rigidbody.AddForce (transform.forward * (Input.GetAxis("Vertical")*100000));
double vel = rigidbody.velocity.magnitude * 3.6;
txtVelocity.text = "Speed: " + vel.ToString() + "km/h";
txtGroundDistance.text = "Distance to ground: " + distanceToGround.ToString() + "m";
txtGravity.text = "Hover force: " + gforce.ToString();