Balancing around Z axis

Hi there,

I’m trying to automatically balance out a hovercraft thats driving and jumping over large hills. I’ve setup keys to turn the vehicle around the y axis, and tilt the vehicle forward and back on the x axis. But the vehicle can wildly roll on the z axis, which is undesirable.

I’ve setup the following code so the vehicle automatically correct itself to Zero (as well as a basic print command to tell when its happening). But I’m really just following my nose, as I’m a C# beginner.

if (transform.eulerAngles.z > 10 || transform.eulerAngles.z < -10)
			{
			transform.eulerAngles = Vector3.Lerp(transform.eulerAngles.z, Vector3.zero, Time.deltaTime);
				print ("z" + stoppedCount++);
			}

its currently not working and getting the error message “The best overloaded method match for `UnityEngine.Vector3.Lerp(UnityEngine.Vector3, UnityEngine.Vector3, float)’ has some invalid arguments”

Any help, info or direction would be greatly appreciated, as I don’t even know if I’m heading in the right direction.

Thanks dudes!

The error means that you are putting the wrong parameters into Vector3.Lerp(Here, Here, Here);
As the error tells you, it wants first a Vector3, second a Vector3, third a Float.
What you put as first is only the Z which is one out of 3 Floats contained in a Vector3.

So just remove “.z” from the first argument in your Vector3.Lerp.

transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, Vector3.zero, Time.deltaTime);