Sign in to follow this  

Autonomous Entities

Recommended Posts

Ok, I'm a little stuck creating my autonomous entity, in visual basic. It's nothing special really, I just want it to avoid collision better. Right now, my algorithm is flawed, in that it allows the agent to cross over a boundry too often. I really just need theory, my current algoritm checks with an invisable line (probe) from the outside radius of the agent to the agent's velocity*25 (a number I choose because it estimates well). It does this in a loop, and checks each pixel in front of the agent. if there is a collision between this line and a boundry, the velocity is lowered and the heading is changed (+15 degrees). This isn't producing the results I wanted, perhaps it has something to do with timing the braking properly, and/or changing the heading in the right direction /w the right ammount of change. Or maybe I shouldn't check each pixel, and there is a better method? One last thing, is there a specific formula for determining the + or - number of degrees from an object with a position and heading (x,y @ heading) and a point (x,y). Basically for turning to a goal. Thanks!

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Erm... everybody else check me on this, as I'm a little out of it right now.

To steer TO a goal point from a spot...

First, find the angle:
1. Create a vector from your current direction to the goal point.
2. Find the dot product of the two vectors.
3. Take the arccosine of the dot product.

Second, to see which direction it is in:
1. Find the cross product of the heading vector and the goal vector
2. Once you have the cross product, you can find out which way the angle is...
3. If cross product is negative, than its a left turn (+); if positive, a right (-).


I hope that works... if you have a problem with it, its gonna be in step 2.3, where you use the cross products, in which case you'll probably just need to switch what you do with it (i.e., you'll need to switch it to make sure that it returns a + when it should and not a -).

If it doesn't work, someone please point it out, as I am writing this at around four in the morning while simultaneously trying to pound out more AI code for my company's project, and I am totally burned out.

Share this post

Link to post
Share on other sites
Ok, so I'm having a little trouble with this because there are from what I see multiple equations. First being A @ B = AX*BX + AY*BY (let @ be the dot product). So that is the dot product, but from that the following equation can be satisfied A @ B = |A| * |B| * Cos(Theta). I can further derive it to this form:

(AX*BX + AY*BY) <-The dot product
ArcCos -------------- = Theta (The angle difference)
|A| * |B| <-The multiplied lenght of vector a & b

So it got screwed up, but so far is that right? To the angle take the ArcCosine of the dot product divided by the multiplied lenght of vector a and b? Then after I find the angle, I find if I should turn left of right with help from the cross product? Then I just turn left or right until I reach that angle? I'm also having trouble with the cross product, from what I understand it is A X B = AX*BX - AY*BY, however, do I use that or this equation
A X B = |A| * |B| * Sin(Theta), to determine to turn left or right?

[Edited by - Anidem on June 5, 2005 1:53:09 PM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
It's important to realize that the cross product (A x B) is a vector perpendicular to the plane spanned by A and B. What matters here is the z-coordinate of this vector. In 2d you get a vector perpendicular to the XY plane.

| Ex Ey Ez |
| ax ay 0. | = (ax*by - ay*bx) Ez
| bx by 0. |

(Ex, Ey, Ez being the unit vectors in x,y,z direction)

So the size of this vector is (ax*by - ay*bx) = |A|*|B|*sin(theta). So in a 2d situation you can simply look at the sign of (ax*by - ay*bx). When it's positive, A is on the right side of B, if it's negative it's on the left.

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

Sign in to follow this