- Home /
Question by
Trild123787898 · Feb 19, 2020 at 05:00 PM ·
script.
problem when turning the object
I have object1 that I am making a turn, and there is another object2 along the way, I need that when object1 collides with object2, object1 can make a turn only in the opposite direction, so that it cannot go through!
here is the object rotation script
if (click_detail3 == true)
{
detail3.Rotate(new Vector3(0, 0.3f, 0));
}
if (click1_detail3 == true)
{
detail3.Rotate(new Vector3(0, -0.3f, 0));
}
Comment
Consider creating a class for this object, say Turner. Give it a class property like float direction = 1f. Add OnCollisionEnter(), and flip direction via direction *= -1f. Then inside the single new Rotate vector, multiply your y * direction. Good luck!
Your answer