My object is rotating (2.5D game) (FIXED)

Hi everyone. I am trying to make a 2.5D game. I have a player object (rigid body, and I have added the ‘Freeze Rotation’ to it, no gravity) and it moves to the right side of the level. Then player hits something (different object) it goes to the beginning of the level.

The problem is each time it hits something it slightly moves to the right or to the left and after some time it’s to far away from the incoming objects.
How can I fix it? I have tried adding rotation script to it but it didn’t help. :frowning:

//This is my script://

var speed : int;
var goUp : int;
var gravitation : int;
function Update ()
{
//movement script
goUp = goUp + 1 * Time.deltaTime;
transform.Translate(0,-gravitation * Time.deltaTime,speed * Time.deltaTime);

if (Input.GetKey(“up”))
{
transform.Translate(0,goUp * Time.deltaTime,0);
}
}
// Collision detection
function OnCollisionEnter (hit : Collision)
{
if(hit.gameObject.tag == “Path”)
{
gameObject.transform.position.x = -240;
gameObject.transform.position.y = 10;
gameObject.transform.position.z = 0;
}
}

THANKS A LOT FOR YOUR TIME.

Well, it’s more of a problem of translation, not rotation. What you need to do is hard-code in a specific position on the x, y, or z axis (whichever has the problem) and assign it every frame.

okay… How do I assign each frame same axis ?

Since you are moving the object by its transform, you shouldn’t have a rigidbody component on it - it will only cause you trouble.

If someone is interested. I made game work properly. Just added few lines which made sure the object stays on the x Axis.

if((transform.position.z >= 0.01) || (transform.position.z >= -0.01))

{
transform.position.z = 0.0;
}