Unity3d: calculate the result of a transform without modifying transform object itself

Posted by Heisenbug on Game Development See other posts from Game Development or by Heisenbug
Published on 2012-10-17T11:09:54Z Indexed on 2012/10/17 11:23 UTC
Read the original article Hit count: 368

Filed under:
|
|
|

I'm in the following situation:

I need to move an object in some way, basically rotating it around its parent local position, or translating it in its parent local space (I know how to do this).

The amount of rotation and translation is know at runtime (it depends on several factors, the speed of the object, enviroment factors, etc..).

The problem is the following: I can perform this transformation only if the result position of the transformed object fit some criterias. An example could be this: the distance between the position before and after the transformation must be less than a given threshold. (Actually the conditions could be several and more complex)

The problem is that if I use Transform.Rotate and Transform.Translate methods of my GameObject, I will loose the original Transform values. I think I can't copy the original Transform using instantiate for performance issues.

How can I perform such a task?

I think I have more or less 2 possibilities:

First

Don't modify the GameObject position through Transform. Calculate which will be the position after the transform. If the position is legal, modify transform through Translate and Rotate methods

Second

Store the original transform someway. Transform the object using Translate and Rotate. If the transformed position is illegal, restore the original one.

© Game Development or respective owner

Related posts about unity

Related posts about matrix