Monday 23 September 2019

Programming Adventures 2 - Unity3D Translation

Programming Adventures 2 - Unity3D Translate

When moving objects using gameObject.transform.translate(x,y,z), its direction is based on the object's local transformation.

That means that a square object rotated 90 degrees right will translate +Y when translated by (10, 0, 0).

This bug happens when trying to translate objects using world space vectors.


Solution

The solution is to use gameObject.transform.SetPositionAndRotation( gameObject's position + translation direction, __); this avoids the local transformation stack!

No comments:

Post a Comment

The difference between class and object.

 The difference between class and object is subtle and misunderstood frequently. It is important to understand the difference in order to wr...