- Home /
The question is answered, right answer was accepted
OnTrigger AI projectile detection and turn.
Ok I need to get my AI to notice bullets being shot into his line of sight and him.
He has 2 colliders, one is a trigger which is the vision collider and the other is the capsule collider on the AI itself(not a trigger).
What I need is this fool to detect or reference the angle at which the bullet is shot at him and start moving in that direction.
Code so far:
void Update(){
if(startSearching == true){
Searching();
}
}
//The hell am I doing lol? I don't know.
void OnTriggerEnter(Collision colp){
var contact = colp.contacts[0];
if(status == Status.Idle){
targetDirection = Vector3.Reflect(transform.forward, colp.contacts[0].normal);
startSearching = true;
}
}
void Searching(){
// This makes it go forward.
vSpeed = 1;
// and this is the turing to contact point.
tansform.rotation = Quaternion.LookRotation(targetDirection);
}}
So what I am trying to say is... This whole thing does not work, I am very confused and please halp!!
Ok it works but now its conflicting with the other stuff. However that should be easy to fix, thanks... I hope.
Thanks.
Answer by sdgd · Aug 22, 2013 at 05:47 PM
java is not my best lang so I'll try to explain in comment
first
Vector3 pos;
void OnTriggerEnter(collider Bullet){
pos = Bullet.transform.position-transform.position;
}
something along this lines and first you'll figure out at what direction he's being shot at and after that you make him move in the opposite direction.
well depends what you actually want, ...
since I've been helpful i'm converting to an answer and here's some more information:
and you propably need to make another GameObject with only collider and attach the script to it (that will be a bullet detection collider).
if you give collider with witch AI is standing on "earth" a trigger you'll see the enemy AI fall down. so at least 1 collider must not be trigger.
, ... you closed the Q and said the right answer was accepted
I don't see it accepted tho, ...
you accept it with the check mark under the thumbs down.
and after that my answer becomes green.