- Home /
Question by
Xarathorn · Jan 27, 2014 at 02:38 AM ·
javascriptvelocityteleport
Velocity not resetting to zero?
The ball keeps rolling in the direction it was prior to teleporting. The velocity is just about halved rather than being completely reset. Any ideas on why this may be?
#pragma strict
var maxFallDistance = -1;
var maxJumpDistance = 30;
var startlocale:Vector3;
function Start(){
startlocale = transform.position;
}
function Update () {
if ((transform.position.y<=maxFallDistance)&&(transform.position.y<=maxJumpDistance)){
rigidbody.velocity=Vector3(0,0,0);
transform.position=startlocale;
deathCounter.deaths += 1;
Coinpickup.coins = 0;
}
}
Comment
Best Answer
Answer by zharik86 · Jan 27, 2014 at 08:20 AM
As far as I understood, after a teleport the full-sphere shall be in rest. You wrote everything correctly, only you forget that it is a full-sphere. It has two component velocity: velocity of center of mass and angular velocity. You need in yours a condition to deliver in 0 angular velocity. Add the next line:
if(...) { // your condition
...
rigidbody.angularVelocity = Vector3(0, 0, 0);
}
I hope it to you will help.