- Home /
Destroying a Character
I need help adjusting the way two characters using Character Controller and FPS walker work.
I've made it so that they'll register when they collide into one another, they will check what the terrain is like. If certain objects are present, the first one will be destroyed but not the second one. IF they aren't present, the second character will be destroyed, but not the other.
I don't think they're registering each other's presence. Nothing I'm doing seems to get one to destroy the other.
this is the code I'm using:
var hit : RaycastHit;
function OnTriggerEnter(CollisionInfo : Collider){
if (collision info.gameobject.tag == "Samurai"){ if (Physics.Raycast (transform.position, new Vector3(1,0,1), hit, 10) ){ if (hit.collider.gameObject.tag=="Shadow") { Destroy(collisionInfo.gameObject); } else { Destroy (gameObject); } } } }
I think I know PART of the problem, which is I have two objects using CharacterController, and not one object with CharacterController and one with some collider in it, but I have no idea what I'm supposed to do to fix the problem.
Could you post the code you are using so we can check if there are problems (and if there are, what they are)? This would make our task much easier, because there are many ways you could complete this task.
done, added it. The goal is to make it so that if a wall object is present (one that would simulate there being a shadow) then the samurai character will die by running into the ninja. If there is no wall (tagged Shadow) then the ninja will be the one destroyed.
Answer by Adam Rademacher · Oct 24, 2010 at 09:53 PM
First, OnTriggerEnter returns a collider, the collider that entered the trigger. You probably want to use OnCollisionEnter or OnControllerColliderHit.
alrighty, so that would solve the problem of two character's colliding?
Absolutely. OnTriggerEnter is called when a collider enters another collider that is marked 'trigger' in the inspector. Character controllers are a special type of collider and can't be a trigger, so two hitting each other won't register.
Answer by shadowclasper · Oct 24, 2010 at 10:45 PM
Okay. I'm simplifying the code to the point where it's just "if ninja touches Samurai, then print 'Hit'" just to test to see if it's actually happening.
I figure the code SHOULD look something like this:
function OnControllerColliderHit(hit:ControllerColliderHit){
if(hit.gameObject.tag=="Samurai"){
print("hit");
}
}
It is still not working. Any suggestions?