Instantiate Rotate with certain axises

I probably sound annoying right now XP Soooo many problems, eh? Anyways, for one of my mechanics, I want an object instantiated at a certain angle. What I mean is, I want my instantiated object to appear at a certain angle, depending on where it pops up:

var instantiatedPlatform : Rigidbody = Instantiate (myObject, transform.position, transform.rotation);

So if I hit a dedicated object from the west, it will face me directly, and from the south, facing towards me again, and if I were above the object it will face up at me. (It would always look like it’s staring at me)

The code above puts my object at weird angles. Because my object is at a 270 angle to begin with, it flips it sideways. However this means that my object rotates in every direction, I only want it to rotate in two directions, up and down and side to side.

Think of it like a car and a plane, I want it to rotate like a car. Turn left, Turn Right, Going up a hill, and Going down a hill. But it’s rotating like a plane, where it can do all of the rotation directions above, but with Roll Left and Roll Right.

Well, sounds to me like you want no Z rotation (Z ends up being the roll you’re getting).

What I would do is use LookAt and then zero out the Z degrees manually. This might be a sloppy solution, or something that doesn’t always work, but it would be what I would do (an inferior programmer to say the least).

var instantiatedPlatform : Rigidbody = Instantiate (myObject, transform.position, transform.rotation);

instantiatedPlatform.LookAt(transform.position);

//And if you want no pitch/roll
instantiatedPlatform.eulerAngles.z = 0;

However, what’s the purpose? There could be a better solution. Also, if all you need is for it to always look directly at you, why not just use LookAt? Does it need to be aligned with your local Up axis? Also, why are you instantiated at the transform position without an offset to make it below the char? Currently, with it being in the same position, its always looking at the transform because they share the exact same location. Anyways, get back to me when you can and we’ll go from there ;), if I am any help at all. Ha

As you can tell from the script, it’s a “Platform” Right now the platform, when it instantiates, it’s appearing at a weird angle (rolled to its side), for my game, my character is never rolled over to the side, so I won’t be able to fix that problem with the character. And the object already being at an angle comes from the way the object imported. The object already faces me when I use transform.rotation, but it also resets my object’s axises to zero, thus resulting in my weird angles.

----And I found out that the objects it hits has something to do with it too (My clouds flip the axis all crazily and my flat surfaces of my house doesn’t)

—At this current moment all I did was flip the object’s axises in max, but I do want to know the scripting.

Well to be honest, you’re kind of losing me. It seems to me if your problem was the max import settings maybe you should bake the rotation in max and then export it to unity so when the rotations zero out(in unity) it’s correct in it’s orientation. Also, can the LookAt(player.transform.position) not work? Right now i’m pretty confused as to what the problem is. If its because of the funky import rotations, fix it in max first.

And whats this about the objects it hits…? Is it a rigidbody? Or what’s going on… Lol. I need more quality info :wink: