- Home /
Collision between 2 Players while playing animations
Good evening
I'm a complete beginner at Unity. I want to program in my game, if Player1 plays a stroke animation for example and hits the HitBox of the other while executing the animation, Player2 should play another animation for example a step back. How can this be programmed?
I would appreciate any advice or tip, no matter how small.
$$anonymous$$an, you said you are a complete beginner, so i don't even know where to start, there are a lot of details in doing that, wich i don't know if you are aware of, so what i can do to try in helping you is this:
https://www.youtube.com/channel/UCYb$$anonymous$$_tjZ2OrIZFBvU6CC$$anonymous$$iA
This links to really good youtube channel, if you complete 1 or 2 of the basic tutorials avaliable there you should be able to complete this task you want easily
Answer by kreaturian · Jun 17, 2019 at 08:08 AM
What i would do is run an OnCollisionEnter function. (https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html) And in the OnCollisionEnter function, I would run an if() statement. For example
void OnCollisionEnter(Collision other){
// Check to see if the object is touching the enemy
// Don't forget to make all of the objects containing the hitboxes of P2 have the tag "P2"
if(other.gameObject.CompareTag("P2")){
//play enemy's animation
}
}
Your answer
Follow this Question
Related Questions
Collider on Bone changes Bone Origin/Pivot 1 Answer
How do I make animation transitions a one-way street? 1 Answer
How to trigger an event if the collided object has the tag “Player” 3 Answers
Can I make animations snap to a frame? 1 Answer
How to let the player collide with animated objects? 0 Answers