ricardojmendez / UnitySteer

Steering, obstacle avoidance and path following behaviors for the Unity Game Engine
https://numergent.com/tags/unitysteer/
Other
1.21k stars 277 forks source link

How would you use UnitySteer for guided missiles #32

Closed Indiefreaks closed 9 years ago

Indiefreaks commented 9 years ago

Hi,

I've been using UnitySteer for quite a while now, and I'm getting some issues using it for my missiles. So before I totally change my mind and implement some simpler predictive steering behavior, I wanted to ask for help.

So this isn't a bug nor a feature request but a real quest for help ;)

I created a simple sphere gameobject which will act as my guided missile. I attached to it an Autonomous agent, a Spherical collider and a SteerForPursuit component. I then simply set the target to the SteerForPursuit behavior and implemented a simple Missile class which would capture the OnTriggerEvent to apply damages, explosions and all the fancy stuff.

Now, what happens is that the Pursuit isn't suited for that as it'll use the Arrival radius of the target agent and I may use it for something else. Moreover, if I set the Arrival radius to 0, the missile actually goes through the target but the TriggerEnter event is never raised and I don't get why...

Thanks in advance.

ricardojmendez commented 9 years ago

Hi,

You may want to check the comments. Setting the arrival radius to 0 will not help, since SteerForPursuit doesn't consider the arrival radius but its own "acceptable distance".

Also, when ArrivalRadius is considered, setting it to zero will be counter productive given that the distance will always be larger, so it would never actually stop.

Can't say why Unity isn't sending you an OnTrigger message, but that would not be UnitySteer related - have you checked the table on the cases of where the messages are fired? You may also want to use the AcceptableDistance on SteerForPursuit, and hook up to that behavior's OnArrival event which will tell you when it stops pursuing, detonating the missile then.

Indiefreaks commented 9 years ago

Thanks @ricardojmendez I'll have a deeper look at the comments and let you know how I did solve this. Cheers

ricardojmendez commented 9 years ago

Cool. And if you figure out why Unity isn't sending you the OnTrigger, please add a comment in case other people run into it. I've found that to happen where the colliders overlap during only one frame, so if your colliders are small or the object is moving too fast, that might be the case.

Just in case, about OnArrival: It gets fired the first time a steering behavior will return a zero force after moving. Note that this doesn't mean the vehicle has arrived, since there might be other contributing behaviors, only that a particular steering has decided the vehicle is where that steering wants it to be.

Indiefreaks commented 9 years ago

I actually found why : adding a simple Rigidbody component to my missiles fixed it. Simple yet not required "normally".

ricardojmendez commented 9 years ago

If both were static colliders, the trigger events would not have been raised.