//Push player if they come in contact
var bounce : boolean = false;
var bounceAmount : float = 10;
var Player : Transform;
function OnCollisionEnter (other : Collision) {
if(other.gameObject.tag == “Player”);
{
bounce = true;
}
}
function Update ()
{
if(bounce) {
Player.rigidbody.velocity.y = 0;
Player.rigidbody.AddForce(0, bounceAmount, 0, ForceMode.Impulse);
bounce = false;
}
}
I added the above script to my player controller and created a cube with tag “Player”. It does not react when I collide with the cube. Help please
Did you attatch a rigidbody to your player?
Try to increase the bounce value to a higher one like 10000 and see if it works, also you should use FixedUpdate() instead of Update() when handling physics.
Tried that and nothing!!! Any other suggestions?
if(other.gameObject.tag == "Player");
{
bounce = true;
}
}
you have a ; behind your if() statement. you should remove that.
Still no GO
I added it to a cube and tag tge camera with “Player” and I did the reverse. Still no go. What gives?
Can you create a simple scene with this code and post a link to it. Not sure what I am doing worng. Thanks
//Push player if they come in contact
var bounce : boolean = false;
var bounceAmount : float = 10;
var Player : Transform;
function OnCollisionEnter (other : Collision) {
if(other.gameObject.tag == “Player”)
{
bounce = true;
}
}
function Update ()
{
if(bounce) {
Player.rigidbody.velocity.y = 0;
Player.rigidbody.AddForce(0, bounceAmount, 0, ForceMode.Impulse);
bounce = false;
}
}