Locking an objects movement on a desired axis, disregarding any external forces.
I have 2d sprites what have 3d colliders, and control in 2 dimensions along 3d platforms. When 2 characters collide, they often get pushed little by little along the z-axis. I want to stop this. I've tried using rigidbody to disable it, I've tried using a script to reset the transform.position on the z-axis, all to no avail. Does anyone have a good idea on how I can achieve this? whether it be resetting the transform, or locking movement alltogether. Thanks in advance. Here's what I tried:
//re-align on z-axis
if ( transform.position.z != -0.500f )
{
transform.position = new Vector3( transform.position.x, transform.position.y, -0.500f );
}
Similar questions have been asked in the past but none have worked so far.
Your answer
Follow this Question
Related Questions
Make object move back and forth 2 Answers
how can I move an object around a parent object manually? 0 Answers
Stop moving gameObject and push it back 0 Answers
Player teleport not working 0 Answers
How to move gameObject along a Vector3 with OnMouseDrag()? 0 Answers