- Home /
Character Controller, and a Enemy.
I have 2 things in my project. A main character, and a enemy. My main have a Character Controller and a Third Person Controller script, a Rigidbody, and no Colliders [character controller has one]. My enemy have a box collider, and a script that say if my main character collide with him, it will do the "hit" animation, and will be "destroyed". Not worked. After a lot of work, I discovered that the supposed problem is the ''Character Controller'' Collider not work too good. What I supposed need is to erase the third person controller, and the character controller, but with myself, the ''Third Person Controller'' works very well with the Main Character movimentation. But I don't want to make a new script to the character move with W,A,S,D, and make the determined animations that I have attached to it. What I can do to my enemy recognize the Collision?
#pragma strict
var idling: boolean = true;
function Start () {
}
function Update () {
if(idling)animation.Play("Principal");
}
function OnCollisionEnter(collision: Collision)
{
if(collision.gameObject.tag == "Player")
{
animation.Stop();
idling = false;
animation.Play("Hit");
Destroy(gameObject, 2);
}
}
Sorry for my horrible English, I'm Brazilian. Thnx for help!
Difficult to say from what you've shown us, you're saying the OnCollisionEnter isn't working but that's really all we can see.
So just try a few things.
Try adding a
Debug.Log("Collided with " + collision.gameObject.tag);
So it reports if it hits anything.
Also try adding a collider to your character.
check the isTrigger isn't ticked on the enemy collider, if it is then either untick or change OnCollisionEnter to OnTriggerEnter.
$$anonymous$$aybe add some screen shots of the Character/Enemy Inspector windows if none of that helps.
PS Your English is pretty good :¬)
I have this:
Collision Bug - http://prntscr.com/5n0mw5 Enemie Config. - http://prntscr.com/5n0n89 Enemie Script - http://prntscr.com/5n0nea Player Config - http://prntscr.com/5n0nn5
Answer by ramp · Jan 01, 2015 at 08:30 AM
hi,
Attached Rigidbody to Enemy.
Add that Debug.Log statement I suggested, add it before the if statement that checks the Player tag.
Also I'm not familiar with JS as I code in C# but you should be able to use collision.tag rather than collision.gameObject.tag
Try adding both lines but add them before the if statement.
See what results you get in the console.