Advertisement

Obstacle avoidance steering behavior: is my math wrong?

Started by November 07, 2019 02:27 AM
5 comments, last by Zurtan 5 years, 1 month ago

I am trying to implement obstacle avoidance in unity as follows: I fire a series of parallel raycasts in the players moving direction, get the closest hit and then multiply hit.normal by steering force to get an avoidance vector.Then I use prioritization blending(have some max steering, I add obstacle avoidance steering first and then add seek steering towards target if I have not already reached max steering). The problem is that If the player is directly behind the wall then the seek direction and hit.normal(aka avoidance direction) is in opposite. Hit. normal seems to work if obstacle is far away but not much so if the obstacle is near. Am I supposed to calculate some other way?(normal component of hit.normal on my velocity vector maybe).

And is it better to have  cone raycasts instead of parallel ones?

What do YOU do as a human in that case?

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Advertisement
3 minutes ago, IADaveMark said:

What do YOU do as a human in that case?

If the wall is to the right, target is also further right and wall is perpendicular to that direction I'd steer in that perpendicular direction. But How do I calculate that perpendicular direction in code?(My vector maths knowledge is a bit lacking)

You can use dot product. If two vactores are orthogonal then dot product is 0. If they are moving away from each other or have wider angle than 90 then thay are negative. You can use that to test if two direction are moving away from each other. You can also calculate the normal to your vector to test if the direction is left or right to the other vector.

Hope this helps.

2 minutes ago, Zurtan said:

You can use dot product. If two vactores are orthogonal then dot product is 0. If they are moving away from each other or have wider angle than 90 then thay are negative. You can use that to test if two direction are moving away from each other. You can also calculate the normal to your vector to test if the direction is left or right to the other vector.

Hope this helps.

So assuming I am moving direction is transform.forward, and my perpendicular direction in my moving plane is transform.right, if I hit something, I need to move along or opposite transform.right. I then check the dot product with transform.right, If it's +ve I need to steer in the direction of tranform.right, if it's -ve I move in the opposite direction of transform.right. Is that correct?

The direction will help you figure out when it's hitting and when it's going away from each other.

If it's going away from each other, then you don't need to fix the position otherwise it will stick.

I am not sure that is a good way to HANDLE the collision, I just suggested how you can detect objects colliding while going into each other, instead of moving away from each other.

I think the easiest way to do this, is try to divide your frame into smaller steps, and move everyone in smaller steps.

This topic is closed to new replies.

Advertisement