Game Development Community

AI distance from player.

by Denis Linardic · in Technical Issues · 10/08/2004 (11:14 pm) · 23 replies

Hi!
I have a little problem, still learn scripting so this AI stuff is pretty much new to me.
I would like to stop the bot before it reaches me.
Example:

I have some trrigers setup which spawns three bots on the nearby hill and the bot automaticly start running toward me with desire to kill me (they are doing good job, well too good).
Now I would like to stop them before they reach me and make them strafe left or right.

Strafing is not that important at the moment, but stoping them it is, so if you have any idea please help. I am not asking for full solution (altough would be nice) but only some pointers :)

Thanks.
Page «Previous 1 2
#1
10/09/2004 (7:36 am)
You can use vectorSub to create a vector that will have the distance from your player and the bot. VectorLen will give you the size of the vector.

You can either check if your bot is near enough the player by checking the distance thru the vector lenght. Or you could normalize the vector, multiply it by the distance you want from the player and set the bot destination to that point.

HTH
#2
10/09/2004 (9:22 am)
Bruno, would you mind elaborating a little more, I'm getting some good results from your suggestions, but I can't seem to get quite what I'm looking for and I'm wondering how you might work your positioning code.
#3
10/09/2004 (5:12 pm)
%botpos = %bot.getTransform();
%mypos = %player.getTransform();

%distance = abs(VectoLen(VectorSub(%botpos,%mypos)));

if(%distance <= %limit)
//stop, strafe, %bot.state = aiming
else
%bot.setMoveDestination(%mypos)

OR

%botMoveVector = VectorNormalize(VectorSub(%botpos,%mypos))*%limit;
%botDestination =VectorAdd(%mypos,%botMoveVector);
%botl.setMoveDestination(%botDestination);
#4
10/10/2004 (6:49 am)
Hi ive been at this loads and tried implement it but the limit is wierd what is it
limit = 1;
limit = "1 1 1";
?????????????
cheers
#5
10/10/2004 (7:00 am)
Hi ive been at this loads and tried implement it but the limit is wierd what is it
limit = 1;
limit = "1 1 1";
?????????????
cheers
#6
10/10/2004 (7:08 am)
%limit should be the distance between the player and the bot ( in meters )

something like 3 or 5.

depends on your needs.

But I wrote it wrong, you shouldn't multiply a vector by a number in the script. Use vectorMult(%vector,%limit)
#7
10/10/2004 (5:52 pm)
Hey bruno sorry to be a pain but i look round and didnt find that vectorMult anywhere. do you code it yourself..
not being bad just got loads other problems your help is much appreciated and ill try find the fix in the mean time.
#8
10/10/2004 (6:32 pm)
Use %resultvector = VectorScale(%vector,%limit)
#9
10/11/2004 (3:29 am)
Thanks, for your help, however as I said I am new to all this so I have difficulties even to understand your answer :(

Where do you create vector? I tried in aiplayer.cs but for some reason it doesent work.
#10
10/11/2004 (5:59 am)
Denis,

You should try Ken Finney's book "3D Game Programming All in One", it will certainly help you.

To create a vector all you need is an XYZ triplet, such as "5 4 1".

If you do :

%botpos = %bot.getTransform();
%mypos = %player.getTransform();

%vector = VectorSub(%botpos,%mypos);

you will create a vector that points from %botpos to %mypos.

you should create it where you need it. In this case in the AIPlayer.cs, inside the function that calculate what your bot should do.
#11
10/11/2004 (8:24 am)
Thanks, I've purchased the book and it arrived few days ago, so I am learning all this a little faster than I did before.
Well few more years and I will become expert in "Torque script" :)
#12
10/17/2004 (2:24 pm)
Ok I finnaly figured out :) I took a while:) Thanks Bruno!

3DGPAi1 is great, too bad it doesn't tell a little bit more about AI.

I was messing with getposition but it seems that getposition don't work:)

Now I am trying %obj.setMoveDestination <--to move a bot toward's my position. I am placing that in AIPlayer::OnDamage function but I get error in console. Is there a problem with "setmovedestination"?

The bot's I am spawning ingame through trigger automaticly start running toward me, but the bot's that was spawn on the mission start "don't see me" until I get close enough. Now I am trying OnDamage function (when i shoot the bot OnDamage function informs the bot of my location and move him towards me) however as I said I have problems with setMoveDestination.

Any ideas?
#13
10/17/2004 (6:34 pm)
What are your problems with setMoveDestination ?
#14
10/18/2004 (4:46 am)
I am at work right now but I think it was "can't find function setMovedestination", I will check out when I get home.

It's probably trivial error.
#15
10/18/2004 (4:54 am)
Sounds like you are trying it on the wrong object number being passed to the function or you have a small syntax error such as....

%cilent instead of %client

or some other transpositional error of that type.
#16
10/18/2004 (4:57 am)
Denis send me your trgger code, i will look at this as it sounds like somthing that needs to be done (your still using the sp_starter right)
#17
10/18/2004 (1:22 pm)
@Gonzo

Yes I probably mess up somewhere (never write code when you tired :-) )

@Ace
I am still testing AI methods so this is used in Release 1_3_0 with AI Update (I think you post that resource). However I will import it into Sp starter once it works (I did a lot of work in SP - mostly basic but is fun to play with)

I will send you tommorow (I am not at home today).
Thanks for the help.
#18
10/20/2004 (2:47 pm)
@Bruno
The problem with setMoveDestination was my stupidity :-)
I,ve fixed that, still have some problems (bot is not going directly to me altough he's passing close enough, and sometimes he is running backward :) acctualy that happened only one time :)

Thanks you all for you help and patience (I am pretty sure that I will come back here realy soon).
#19
10/22/2004 (6:45 am)
Heh, I am back again :)

Thanks to your help my bot is doing some wonderfull things, but still from time to time when i shoot at him he start to run backwards, even if I am behind him. So here are the questions:

Anybody know why would that happened?
What function I should use to make the bot always aim at me (after he notices me)? There is something
like setAimLocation?

And one very stupid question:

When bot is added he is assigned with certain number. Can i extract that ID# inside OnDamage fuction, or I should
save it directly in spawnBot function and the pass it to On Damage? In second case, would there be a problem when there are 30 bot's spawned with 30 different ID#?
#20
10/23/2004 (5:09 am)
There is setAIMObject function that will make the bot follow the player instead of the location.

When you spawn the bots you can save their handles on global variables use $name instead of %name.
if you want to spawn 30 bots, save them in an array $array[%i] where %i ranges from 1 to 30.
Page «Previous 1 2