About Store Forum Documentation Contact
Donations:
327$/mo



Post Reply 
New to AI
Author Message
DreamsInHD Offline
Member

Post: #1
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
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: New to AI
Hi,

It would be a lot more readable if you could post code in correct code tags. smile

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
Find all posts by this user Quote this message in a reply
DreamsInHD Offline
Member

Post: #3
RE: New to AI
Thanks a lot!
03-18-2016 02:40 PM
Find all posts by this user Quote this message in a reply
Post Reply