• Advertisement
Sign in to follow this  

Arrive or Seek

This topic is 4182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, so I have this code for my AI's Arrive function.
Vector2D EGsoldier::Arrive(Vector2D TargetPos)   //Need to improve on this function
{
	Vector2D ToTarget = TargetPos - Pos();
	double dist = ToTarget.Length();

	if( dist > 0 )
	{
		double speed = dist/( 1.3 );
		speed = min(speed, e_dMaxSpeed);
		Vector2D DesiredVelocity = ToTarget*speed/dist;
		Vector2D FinalVelocity = DesiredVelocity - Velocity();

		return FinalVelocity;
	}

	return Vector2D(0,0);
}

It returns the 2D vector where my EGsoldier should go. The problem is, that if there is an obstacle in the way, the soldier has no idea what to do (and subsequently runs into the obstacle and stays there). Can someone help me figure out how to improve this function so that the EGsoldier can get to his destination w/o running into an object?

Share this post


Link to post
Share on other sites
Advertisement
The easiest way in your current approach is to use repulsive fields: the closer your seeker is to a wall, the more it wants to move away from it (perpendicularly). Adjust your potential correctly and you will move around the obstacle.

A more complex way is to use a pathfinding algorithm (such as A*) on the visibility graph of your scene, then have the seeker follow the path until it sees its target directly (at which point you can revert to arrival behavior).

Share this post


Link to post
Share on other sites
In Craig Reynolds "Steering Behavior" algorithms two of the behaviours are Seek and Arrive. There is then another behaviour called Obstacle Avoidance were the vehicle always tries to keep an emty box in front of it. If the box gets filled with some obstacle then the vehicle turns untill the box is emty again. This approch is very simple to implement and works well with other steering behaviours. To see the exact details look at Craigs sight (a quick google search will lead you to it)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement