- Home /
How do i lock out a axis
I am making game that is a top down 2-d game. I only want things to move in x and z, keeping anything from going to y. The problem is, i have the AI set on a waypoint system that uses rigidbodies, and some times when either myself, or other enemies collide with a enemy, it knocks them up or down in the y axis, making them impossible to shoot and kill yet they can still hit me, as they are scripted to aim in all 3 axis which is fine as it is universal and looks cool.
So the bottom line is, how can i lock the objects in x and z and out of y. My thought was to have it keep resting it's y axis every frame in the update function, but i have no clue how to do that, and i fear it would either look jumpy, or make it lag a lot.
Answer by Ashkan_gc · Feb 13, 2010 at 08:18 PM
the best way is to use a configurable joint and lock the motion in y axis. you can do something like this in update with
transform.position.y=0;
but using joints is the correct way.
Well i tried the joint, and all that does is make it so when i run into a enemy they fly up into the air, then back down to their usual height. I also locked Y motion and angular y motion.
@Ashkan, one $$anonymous$$or point - that's Javascript. In C# you can't assign to Y, you have to do: transform.position = new Vector3(x, 0, z)
yes! in C# structs are paased by value so the reference of a vector3 will not be paased and you should get it's reference if you want to set it that way
Your answer
Follow this Question
Related Questions
How do I lock Y Axis movement for Parented Camera? 3 Answers
Camera moving in one direction? 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
2D, lock the "y" axis 1 Answer
2D Player Movement 1 Answer