DreamsInHD
Member
|
New to AI
Hi,
I'm trying to make an AI, and i'm having some trouble.
I tried to make it walk towards me until it reached a certain distance.
I thought that making it walk in the direction of the line i made between the[/code] position of the player and the ai, but i don't know how to do that. This is what i tried, it kind of works, but it's not perfect. (beginner)
[code]
Edge dir;
bool update()
{
dir.set(ai[0].pos(), players[0].pos());
if(Dist(players[0].pos(), ai[0].pos()) > 3)
{
input.turn = dir.dir().xz();
input.move.z = 1;
if(dir.dir().z < 0)
{
angle.x = dir.dir().x + PI;
}
else
{
angle.x = -dir.dir().x;
}
}
else
{
input.move.z = 0;
}
return super.update();
}
[code]
Thanks in advance
|
|
03-18-2016 12:09 PM |
|
Tottel
Member
|
RE: New to AI
Hi,
It would be a lot more readable if you could post code in correct code tags.
Let's see.
1. Don't use Edge to indicate a direction. What you want to use is a vector (Vec).
2. Since you will use a vector, you can use vector math to get the direction from AI to the player.
Code:
Vec dir = players[0].pos - ai[0].pos; // This is a vector from the ai to the player
dir.normalize(); // Normalize the vector to get only direction (remove length)
Now, it's as simple as calling actionMoveDir(dir) on your ai. Alternatively, you can also use actionMoveto(..) and pass a world position. This would probably give you some more control over where exactly the AI should go to.
(This post was last modified: 03-18-2016 02:33 PM by Tottel.)
|
|
03-18-2016 02:33 PM |
|
DreamsInHD
Member
|
RE: New to AI
Thanks a lot!
|
|
03-18-2016 02:40 PM |
|