- Home /
Restricting Movement To One Axis (Found solutions, but they didn't work)
I'd like to completely restrict movement on a specific axis since I am making a 2d game. After searching around it seemed that the two common fixes to this problem are:
Use the rigid body constraints.
Use the update function to change the axis position to zero.
Neither of these solutions worked for me, and i'm at a complete loss as to where I should even be investigating. Any ideas?
Thanks, Mark
In what way do those not work? Those are how you prevent rotation/movement.
What do you mean by restricting movement can you be more specific?
restricting a rigidbody animation or physics object?
Something that is probably worth mentioning is that I am attaching images to planes. I thought that maybe if I was to use cubes ins$$anonymous$$d that it would help, but it didn't...
It is a plane with a rigid body attached? and i'm not sure why they aren't working, but they definitely aren't. That's why this is so frustrating, I can't find one other person that's ever had a problem close to this.
I was thinking that maybe my problem has something to do with quaternions. I read that the rigid body constraints can be "overridden" pragmatically? So the physics engine might contradict what your script is telling the object to do.... Basically my problem is that my little ship (2d space shooter) goes hay wire, and it happens when I collide with other game objects.
Answer by NowhereStudios · Jan 21, 2013 at 02:41 AM
Ok,
First be sure that your box colliders have a Z scale = 1 (since you are using planes, still you must give a scale)
Then set both objects Z Position equal values.
Then finally on rigidbody, click on Freeze Position Z check to disable movement on Z.
PS: I assume that your camera is directed to Z-Axis.
Answer by MrThunderizer · Jan 21, 2013 at 04:39 AM
Well I wandered off and decided to work on my characters control while waiting for a response, and while doing that the problem somehow disappeared. Unfortunately I have no idea which one of my changes helped. The directions you gave is what I did initially. After that didn't work I attempted to use the update function to change it's position to zero every frame. So yea, i'll just hope that it doesn't reappear.
Thank you for such a clear response, and sorry that I forgot to mark the question.
Your answer
Follow this Question
Related Questions
How to move an object along the X and Z axis with arrow keys/wasd with javascript? 1 Answer
Player launches into air when hitting steep slopes 0 Answers
Make so the script only moves and makes actions to the gameObject that its attached to. 2 Answers
Enemy AI With changing Player 0 Answers
Movement script, moving up when moving positively in z axis 1 Answer