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. ![]()
//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.