Game Development Community

How to make an AI player look at the player?

by Ahmed Zamen · in Technical Issues · 02/28/2008 (5:42 am) · 28 replies

Hi, im trying to get an Ai player to spawn on the map, look and turn to face the player and move only in his place to swivel around to keep the player in view. How would I go about doing this?

Thanks!

About the author

Newport Games and A.I Student

Recent Threads

Page«First 1 2 Next»
#21
03/09/2008 (7:46 am)
The thing is im getting no script errors what so ever when I change the script so I have no clue where to even start adding or deleting code cause im a complete newbie. Ill keep editing regardless though, may have a breakthrough at some point.
#22
03/10/2008 (3:45 pm)
Sigh, no breakthrough, just hours of time getting nowhere. Im still not sure what I have to point to and where I need to declare all this and the more I read Lee's post the more it goes over my head.

Im assuming that as i said above I need to put the player into the localclientconnection.player part of the code, ive tried all variations (that I know of, which isnt many) on this:

%player.client
%client.player


or would i use a global $ instead?

Now where im using those, I guess I have to declare what they contain correct? Now do I do that with its Simobject number or its datablock? If I use $ I could just declare them at the top of the cs file right without any functions getting in the way?

Any direction would be a godsend right now, tutorial's, anything to set me in the right direction, chime in with any ideas I emplore you. Once again I have to thank you for your patience with me and all of your help.

It's a great engine with so much potential, its just being let down by the complete lack of documentation.
#23
03/10/2008 (4:05 pm)
May have something here, I just found the following code from the resources:

function lookAtTarget( %this, %target )
{
   %forward = VectorSub(%target.getPosition(), %this.getPosition());
   %x = getWord(%forward, 0);
   %y = getWord(%forward, 1);
   %angle = -mAtan(-%x, %y);
// make trans from position, axis and angle
   %trans = %this.getPosition();
   %trans = %trans SPC "0 0 1" SPC %angle;
   %this.setTransform(%trans);
}

I think all I need to make this work is to assign the player character to the %target if im reading the code right, as the aiplayer is assigned to %this already, again if im reading it right. Any ideas on how to do this? If it's staring me in the face I apologise, im completely burnt out.
#24
03/10/2008 (4:14 pm)
Okay, let me try a different angle.

First, no, don't use globals ($), that won't work.

Have you tried doing it manually via the console? That is, bringing it down in the mission editor and doing something that looks like:

1994.settAimObject(3830);

Note the numbers are just an example. Go into the mission editor and get the simID's for your bot and your player, then issue the command with the appropriate simID's plugged in.

If you get that working, let me know and I'll show you more to help you understand.
#25
03/11/2008 (2:37 am)
That works, changing the numbers is easy enough, just seeing something working is like a massive weight lifted off my shoulders. Thanks again.
#26
03/11/2008 (4:46 am)
Awesome, dude! I am pleased that we're moving in the right direction.

Okay, now do this:

1. Get the simID number for YOU'RE guy. Let's say it's 1312. Do this in the console:

echo (1312.client);

It will give you a number. Let's say the number is 1210. Now you can turn around and do:

echo (1210.player);

what do you think you will get?

After you do that, try the same thing with the AIPlayer.

Once you grok the system, making it work in script is relatively easy. Once you get the hang of it, you'll be scripting your *** off. It really is a lot of fun.

Mess around with that and tell me what you find.
#27
03/16/2008 (1:27 am)
So hey man, are you off to the races or what?
#28
04/04/2008 (6:31 am)
Hey man, sorry for the EXTREMLY late reply. Thing's have been pretty hectic at home latly, Ill give the above a try on the weekend. Hopefully your still around to give me some pointers!

Thanks
Page«First 1 2 Next»