Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

c# - How to check for sideways car in Unity?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is a quick SUGGESTION: In start store the rotation of the car in a Vector3 variable. After the car is flipped sideways, set the rotation again to the stored value.

public class CarController : MonoBehavior
{
// adjust the angles as per your needs
public float maxLeftAngle = 315f;
public float maxRightAngle = 45f;

void Update()
{
if ((transform.rotation.eulerAngles.z < maxLeftAngle) || (transform.rotation.eulerAngles.z > maxRightAngle))
{
Debug.Log("The car is turned sideways");
// reset the rotation
}
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...