- Home /
constant moving up?
Hi,
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.
What could be the problem?
no, if I remove the Time.deltaTime part, the problem still exists
Answer by Dedede · May 03, 2011 at 03:21 PM
Just for the people, who maybe got a similiar problem:
The problem was the velocity of the rigidbody.
function Update(){
rigidbody.velocity = Vector3(0,0,0);
}
This solved the issue for me.
Answer by Jaap Kreijkamp · Mar 10, 2011 at 10:49 PM
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); }
Your answer
Follow this Question
Related Questions
Collision of a constantly moving object 0 Answers
Underwater effect question 2 Answers
THE FINAL BARRIER OF MECANIM 1 Answer