I’ve looked but obviously don’t know the words to find if this question has been asked before I spawn a game object in front of my controller with a click and when I bump into it nothing. I would like so that when I collide with this box or object that it can… well knocked about but I don’t know the how having been scripting a whole week.
Please answer with some kind javascript with instructions.
This is from the Unity Script reference in the docs:
Note: Make sure the GameObject you are trying to push has a rigidbody
// this script pushes all rigidbodies that the character touches
var pushPower = 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 (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.
// Apply the push
body.velocity = pushDir * pushPower;
}
Thank you for the speedy reply I have been stuck on this problem since lunch. I’ll try it out and I’ll see what I get.