This Javascript code for Unity allows a controller to push Rigidbody objects on collision. When the controller collides with an object, it checks if the object has a Rigidbody component and is not kinematic. If so, it calculates a side-to-side push direction based on the collision and applies a set push power and direction to the Rigidbody's velocity.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views1 page
On Controller
This Javascript code for Unity allows a controller to push Rigidbody objects on collision. When the controller collides with an object, it checks if the object has a Rigidbody component and is not kinematic. If so, it calculates a side-to-side push direction based on the collision and applies a set push power and direction to the Rigidbody's velocity.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1
//Javascript Code For Unity.
Add script to Controller in order to be able to push
Rigidbodys
var pushPower : float = 2.0;
function OnControllerColliderHit (hit : ControllerColliderHit) { var body : Rigidbody = hit.collider.attachedRigidbody; // no rigidbody if (body == null || body.isKinematic) return;
// We dont want to push objects below us
if (hit.moveDirection.y < -0.3) return;
// Calculate push direction from move direction,
// we only push objects to the sides never up and down var pushDir : Vector3 = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.