Unity-Script-Push any object
Publié : jeu. mars 10, 2011 5:48 pm
Push Any Object
Code : Tout sélectionner
//ENG: this script pushes all rigidbodies that the character touches
//ESP: este script empuja todos los rigidbodies que el personaje toca
var pushPower = 2.0;
function OnControllerColliderHit (hit : ControllerColliderHit)
{
var body : Rigidbody = hit.collider.attachedRigidbody;
//ENG: no rigidbody
//ESP: no hay rigidbody
if (body == null || body.isKinematic)
return;
//ENG: We dont want to push objects below us
//ESP: no queremos empujar objetos que esten detras nuestro
if (hit.moveDirection.y < -0.3)
return;
//ENG: Calculate push direction from move direction, we only push objects to the sides never up and down
//ESP: calcular la direccion del empujon desde la direccion de movimiento
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
//ENG: If you know how fast your character is trying to move, then you can also multiply the push velocity by that.
//ESP: si quieres saber como de rapido esta intentando tu personaje moverse, entonces puedes tambien multiplicar la velocidad de empujón por ello
//ENG: Apply the push
//ESP: Aplica el empujón
body.velocity = pushDir * pushPower;
}