I'm trying to get an object to move up, always with the same speed.
I first used a simple
var speed = X;
transform.position.y += speed*Time.deltaTime;
transform.position.z = -0.5; // So that the object doesnt move in depth since it is a 2d game.
The Problem with this is, that if the object hits an obstacle sometimes, not always, the speed reduces itself. If I hit an object again, the speed is constant again.
I froze rotation with the rigidbody, so a rotation towards the camera is not possible.
The issue is that the rigidbody also changes position of the object, in opposite direction your movement. When you use a rigidbody, you better do the movement on the rigidbody, not on the transform, for better physics behaviour.
quick solution:
var position : Vector3;
var speed : float = X;
function Start() {
position = rigidbody.position;
}
function FixedUpdate() {
position.y += speed * Time.fixedDeltaTime;
rigidbody.MovePosition(position);
}