x


Changing the gameobject xyz-axis

Hi,

is it possible to change the xyz-axis of a gameobject?

Say by instance there is a gameobject with the z-axis facing backwards, and you want the z-axis to face forward. Because maybe you would like to create a script with a LookAt() function so it's facing the right direction.

I know you can parent the gameobject in an empty gameobject with the correct orientation. BUT, this adds another problem. That is, whenever you want to destroy the gameobject while colliding with something else, it only destroys the colliding gameobject (and not the empty gameobject, because you don't want to add a collider to the empty gameobject for several reasons). And yeah, I know there are several other solutions to solve these problems (adding tags etc.), but this is really a time-consuming method. Especially when you have lot's of different gameobject that has to do the same thing.

So it would be a lot easier if there was a way to change the xyz-axis in an orientation with respect to the gameobject without adding the gameobject into an empty gameobject.

Is there any way to do this?

more ▼

asked Apr 25 '11 at 11:18 AM

Quantum gravatar image

Quantum
3 4 4 7

As a comment on your empty game object; you can always access the transform.parent, and destroy that. It's maybe another 1 or 2 lines of code tops. Corrective nesting is probably going to be your easiest option, if you can't re-save the asset with a corrected axis.

Apr 25 '11 at 12:14 PM Alec Slayden
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

No, not really. You should always just create your objects so the z-axis faces forward in the first place, saves lots of headaches.

more ▼

answered Apr 25 '11 at 11:35 AM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

I love the simplicity of your answers :)

Apr 25 '11 at 02:08 PM Scribe
(comments are locked)
10|3000 characters needed characters left

Hi,

The only alternative given your requirements is to rotate the mesh vertices themselves, that is: Iterate each vertices of your mesh, and rotate them. In Max, this is actually how it's done internally when you affect the pivot.

I just can't find the script that did that, I am sure someone already build an editor or even run time tool for that, but just can't find it, will edit when I will :)

Bye,

Jean

more ▼

answered Apr 25 '11 at 11:35 AM

Jean Fabre gravatar image

Jean Fabre
3.1k 68 74 103

(comments are locked)
10|3000 characters needed characters left

Instead of changing it it is much easier to just have an empty GameObject.

First: Child this empty gameobject to your original gameobject Then: Reset the transform of your empty gameobject so it centers. Then: Un-child the empty gameobject Then: Rotate the empty gameobject to face the way you want Then: Child the original gameobject to the empty gameobject.

Now you can use this empty gameobject as the original gameobject with the axes fixed.

more ▼

answered Apr 25 '11 at 12:12 PM

Joshua gravatar image

Joshua
6.4k 19 25 70

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2083
x379
x322
x21
x10

asked: Apr 25 '11 at 11:18 AM

Seen: 3624 times

Last Updated: Apr 25 '11 at 11:18 AM