- Home /
OnCollisionEnter Push Object Problem
Hello Unity3D.i have a problem with my OnCollisionEnter Script.The problem is that i can't seem to push my opponent when in contact of an animation.For example.I have a character that does a certain animation that is suppose to send the opponent flying backwards.But when i do the animation to the opponent it plays but the opponent doesn't go anywhere.How can i make it that when my character plays the animation the opponent moves?If anyone knows how i can do this?Can you please tell me how?Because i suck when it comes to pushing object/characters.....
Heres the script.
var player : GameObject;
var enemy : Transform;
var myTransform : Transform;
var Slash : GameObject;
var spawn : Transform;
function Awake() {
myTransform = transform;
}
function Start() {
enemy = GameObject.FindWithTag("Dummy").transform;
}
function OnCollisionEnter(collision : Collision){
if(collision.gameObject.tag == "Dummy"){
if(player.animation.IsPlaying("Sweep_Kick"))
collision.transform.gameObject.animation.Play ("Stand_Air_Hit_back");
Instantiate(Slash,spawn.transform.position,spawn.transform.rotation);
}
if(player.animation.IsPlaying("Violets_Bicycle_Kick")){
enemy.transform.gameObject.animation.Play("Violets_Bicycle_Kick_Hit_Part_One");{
}
}
if(player.animation.IsPlaying("Violets_Bicycle_Kick_Part_2")){
enemy.transform.gameObject.animation.Play("Violets_Bicycle_Kick_Hit_Part_Two");{
}
}
if(player.animation.IsPlaying("Lance_Kick_2")){
if (collision.rigidbody)
enemy.transform.gameObject.animation.Play("Air_Hit_Going_Up");{
collision.rigidbody.AddForce (Vector3.up * 50000, ForceMode.Impulse);
}
}
if(player.animation.IsPlaying("Falcon_Punch")){
enemy.transform.gameObject.animation.Play("Hit_Flying");
}
}
Is OnCollisionEnter even triggered?
Is one of the if statements successfully entered?
Which of them is not working, there's animation plays and AddForces?
function OnCollisionEnter(collision : Collision){
if(collision.gameObject.tag == "Dummy"){ Debug.Log("Colliding") }
check if the collisions are being triggered
Wait they all work its just lines 35-40 that doesn't work.Like when i do the lance kick animation the opponent does it but he does get the force added to him.
The animations play.But the enemy doesn't take force.How can i make it that when my character plays the animation lance kick 2 the opponent that got kick with it goes flying backwards?Like the force is not being added to the enemy
Either the rigidbody is kinematic, or your animation is affecting the transforms position.