Hello Everyone! Newbie question.
How to make an object to rotate to 0.0f by X-axis permanently. I mean if it changes only by X-axis then the object automatically and smoothly will rotate to 0f and stops there until another incline.
I am doing a tank movement and I did script wherein every time the tank moves forward or backward it inclines and Rotation by X-Axis goes less than 0f. I can’t freeze rotations in “Rigidbody/constraints” because it is a child of a blank object with Rigidbody and Box Collider.
I can’t use Quaternion.RotateTowards because I don’t want my object to change its Y and Z-axis. I will appreciate help with C# language!
If you’re using physics it’s best not to mess around with transforms. Either you go all-in on a physics based controller, or not. If you change transforms, rigidbodies are prone to catapulting around if they move inside a collider. This can be avoided with onerous coding but it’s rarely worth the effort.
For a physics-based tank, use e.g. a capsule collider for each track (you can attach multiple colliders to a single gameobject - if you just use a box it will be prone to getting stuck on uneven terrain), and AddTorque or AddForce to it’s rigidbody to move it rather than changing the transform. If you need snappier, less realistic movement, set rigidbody.velocity and rigidbody.moveRotation in FixedUpdate rather than transform properties.