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

Computer Science Reference List

CS Reference List This is a collection of papers, websites and books that I have found useful when researching into computer science. Mainl...