Advertisement

moving bots

Started by April 02, 2001 05:00 AM
4 comments, last by Bruno 23 years, 7 months ago
Hi I''m at the point where i''m now codig the A.I of my bots. I have some waypoints in the map, and the bots move from waypoints to waypoints., but i have one small problem. When they change direction , how can i make them rotate so that they face the direction that they are moving? for example: p1---------------p2 | | | | | p3 My bot is going from p3 to p2, facing p2, when he reaches p2, he starts moving to p1, but he has to rotate -90º so that he faces p1. How can i code this ? I''m using this method. : I normalize p1 and p2, and make a dot product between them. d = dotproduct(p1_normalized,p2_normalized); d = d*180 / pi; But.., not working.. any ideias ? thanks, Bruno
my ascii draw didn''t came out correctly, the browser took away some spaces. Imagine p3 exactly under p2.

thnks,

Bruno
Advertisement
When you say that you normalised p1 and p2, do you mean that you that you took the vector between p1 and p2 and normalised that?

You are almost there, You need to calculate the vector between p1 and p2 - call that v1. You also need to calculate the vector between p2 and p3, call that v2. Then normalise then and do what you have done.

  v1.x = p2.x - p1.x;v1.y = p2.y - p1.y;v2.x = p3.x - p2.x;v2.y = p3.y - p2.y;v1_norm = normalise( v1 );v2_norm = normalise( v2 );d = dotproduct( v1_norm, v2_norm );d = (d*180)/pi;  



---

Fleejay
---Fleejay
Thanks for the reply fleejay, but isn''t it possible to get the angle with only two points?
I mean, if there was no p1, and just p2 and p3, how would it work? The model had to be able to rotate 180 degrees when reaching p2 to be able to face correctly p3..,
any chance to make this with only 2 points?

thanks,

Bruno
You can only draw a straight line between 2 points. However you could store some earlier coordinates of your bot and use them as p1.

If you wanted to only give it p2 and p3 and make your bot walk through p2 to p3, you could save the current bot coordinates as p1 and go from there.


---

Fleejay
---Fleejay
Can''t you express your bot''s facing as a vector?
If you can it is as simple as determining the vector between p2 and p1. If it has to be in degrees then rather than saying rotate -90 degrees I think it''d be easier to tell the bot to turn to an absolute reference, like 90 degrees true. You would need a small bit of code to determine the turning direction, but that would be easy.
If it --has-- to be turn x degrees left or right then it would be easiest to determine the bot''s absolute facing when it reaches p2, determine the absolute bearing to p1, and calculate the difference.
I really think the absolte references are better though. NSEW vs Left and Right.

Good Luck

--------------------------------------
Why run? You''''ll only die tired.
--------------------------------------
--------------------------------------Why run? You''ll only die tired.--------------------------------------

This topic is closed to new replies.

Advertisement