# bot movement problem

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

## Recommended Posts

Hi, First let me try to explain the problem. Supose the player is in the south, and the bot in the north, and the bot wants to move from node x(value 2) to node x1(value 5). Has he his moving from a smaller value to a bigger value, i can assume he his moving left, and i play the walking left animation. If he moves to a higher value, then i play the moving right animation. The problem is, this wont work for all situations, if the player this time is in the north, everything is swapped. Having the bot origin, destiny, angle, direction, how can i know, what animation to play ? Is there a way to mathematically calculate this ? thanks, Bruno

##### Share on other sites
Quote:
 Is there a way to mathematically calculate this?

Yes.

But I'm not clear enough on your terms to tell you what that is. What is a 'node'? Is this in 2D? How are the bot variables you mentioned represented? For how many directions is your character animated (i.e. 4, 8, etc.)?

Anyway, if you can describe your problem in a little more detail it should be pretty easy to solve.

##### Share on other sites
Well, let me try to explain.
A 'node' is a point(x,y), in a grid of 2d positions (x,y)

So, imagine the player in position (0,0), and the bot is in starting point (4,2) moving to (-2,3).
He his moving to the left, so i play the walk left animation.
Now, keeping the same starting point for the bot(4,2) and moving to the same place (-2,3), but this time the player position is at (0,8).
This time, altough making the exact same path, i need to play the walking to right animation.
In both situations, the bot is facing the player, so, he his straffing.
The bot will only need this 2 animations, walking left and right.

bot origin, (x,y), bot destiny(x,y), angle is the angle the bot is facing (0-360), direction, it's just the direction he his moving too.

thanks,

Bruno

##### Share on other sites
Ok, that makes a little more sense. The bot only has two animations, left and right, but he can move in any direction? So as far as that goes, his animation is selected simply by whether his goal x is < or > his current x.

So what does the player's position have to do with it? Do you want the bot to always face the player, no matter which direction he's moving? If so, and if he only has a left and right animation, can't you just choose the animation by whether the player's x is < or > the bot's x?

That seems too simple, so I still must not be getting it.

##### Share on other sites
The player position has to do with it, because if the player is in (0,0) and the bot moving from (-2,3) to (4,2), has he his moving from a x<x1 i play the walk left animation, while looking at the player.
If the player is in (0,8), and the bot still doing the same path, x<x1 he his still doing the same path, but this time on the player point of view, he his moving to the right while playing the walk left animation.
player x position doens't work here, the player can be in any value of x, that the problem is still here.

Imagine yourself in this room

""""""""""""""""""""""""""""""""
".............p1..............."
".............................."
".............................."
"...x.................x1......."
".............................."
".............................."
".............................."
".........p2..................."
""""""""""""""""""""""""""""""""

if you are in p2, and someone walking from x to x1 while facing me, will be walking to his left(walking left animation).
However, if i'm in p1, and the bot makes the same path (x to x1), he will be walking to his right(walking right animation).
So, i do have 2 diferent situations, for the exact same path.
Maybe this was more clear ?
Hard to explain..., i hope you understand :)

thanks,
Bruno

##### Share on other sites
this might not work but it looks like it will

float sx = (p.y-x.y)/(p.x-x.x);float sx1 = (p.y-x1.y)/(p.x-x1.x);if(sx > sx1)	right();else	left();

##### Share on other sites
thanks mike, but it did not work,, altough most of the times it workd :(

##### Share on other sites
Interesting problem.
I think you need to look up the formula for a plane (a 2d one). Then you set one point of the plane as x, the second point as x1.
Then you check if the player is behind or in front of the plane.
This determines which way the robot should face.

##### Share on other sites
plane2d{  vector2 normal;  float d;};

How to intialise the plane given the robots moving coordinates (p1 and p2):
normal=p1.cross(p2)normal.normalise();d = - ( normal * p1 )

Then to test if you are in front or behind:
bool inFront(plane2d& p, vector2 playerposition){float planerelative = (playerposition * p.normal) + p.d;if(d>0.0f) return true;else return false;}

Then:
if (inFront()) drawmovingright()else drawmovingleft();

This _should_ work. In theory :)

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 10
• 16
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632929
• Total Posts
3009277
• ### Who's Online (See full list)

There are no registered users currently online

×