- Home /
Animation OnTriggerEnter
Hello Unity3D.I have a problem with onTriggerEnter.My problem is that i am trying to make my opponent play different animations depending on the animation that the player is colliding with.For example im trying to make my opponent play a "Fall" animation whenever my character plays a headbutt animation and it collides with the opponent.Which code would be better for this situation? OnCollisionEnter or OnTriggerEnter? If anyone knows how to make it that my opponent play animations depending on the animation that the player hits the opponent with.Can someone please tell me how?I have been stuck all day...
#pragma strict
var setOnFire : ParticleSystem;
var player :Transform;
var speed = 30;
var pushPower = 2.0;
var sceneCam : GameObject;
sceneCam = GameObject.Find("MainCam");
function Start ()
{
setOnFire.Stop();
}
function OnTriggerEnter (Col : Collider)
{
if(Col.tag == "Player")
if(!animation.IsPlaying("Headbutt"))
if(!animation.IsPlaying("Sidekick"))
animation.Play("Hit1");
sceneCam.transform.position = Vector3(2.456752, 1.770302,-1.047782);
sceneCam.transform.localPosition = Vector3(0.09087142, -0.4796396, 0.0500228);
animation["Fall"].speed=1;
{
setOnFire.Play();
}
}
I formatted your code to show what it does better. And... what are you trying to do with the brackets around setOnFire.Play()?
Oh Thank you!.Also,What im trying to do with setOnFire.Play is that i am trying to make an impact effect appear.For example.Pow! or Wham or Bop!
Answer by SkaredCreations · Dec 19, 2014 at 05:40 PM
Assign a default animation and change it accordingly to the Col.animation:
function OnTriggerEnter (Col : Collider)
{
if (Col.tag == "Player")
{
// Default hit animation
var anim : string = "Hit1";
// Animation related to player's animation
if (Col.animation.IsPlaying("Headbutt"))
anim = "Fall";
sceneCam.transform.position = Vector3(2.456752, 1.770302,-1.047782);
sceneCam.transform.localPosition = Vector3(0.09087142, -0.4796396, 0.0500228);
// animation[anim].speed=1; // Do you really need to set the speed?
animation.Play(anim);
setOnFire.Play();
}
}
You $$anonymous$$ean This?
#pragma strict
var setOnFire : ParticleSystem;
var player :Transform;
var speed = 30;
var pushPower = 2.0;
var anim: String;
function OnTriggerEnter (Col : Collider)
{
if (Col.tag == "Player")
{
// Default hit animation
var anim : String = "Boeton_Fighting_Stance";
// Animation related to player's animation
if (Col.animation.IsPlaying("Triple_$$anonymous$$ick"))
anim = "Hit1";
animation.Play("Hit1");
setOnFire.Play();
}
}
Because this isnt working
At line 21 you have to assign anim
to Play, not "Hit1"
OHHHHHH.......Ok now it works...Thank You So $$anonymous$$uch!
Accept the answer please, so the question will be moved from queue ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613174405im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
front check based on unity projects not working. 0 Answers
OnCollision Script... 2 Answers
Mesh and Sphere Collider Not Registering 2 Answers
Question on Static Primative vs Mesh Collider Performance 1 Answer