Jump to content
  • Advertisement
Stocke

Obstacle avoidance steering behavior: is my math wrong?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

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.

Edited by Zurtan

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!