AI car that "follows" the player.
ZeroRaven
Member Posts: 33
I've been experimenting with a top down scrolling "driving" style game. An idea similar to the old NES "Spyhunter" game.
I have a NPC car I want to have spawn in that then trys to follow the player and "ram" into them.
Only it seems you cant use the "move to" code to track to another actor.
Does anyone have any idea if I can fix this?
I have a NPC car I want to have spawn in that then trys to follow the player and "ram" into them.
Only it seems you cant use the "move to" code to track to another actor.
Does anyone have any idea if I can fix this?
Best Answer
-
BenMakesGames Posts: 85heres a round about way of how I would do it.
Actors name is spycar.Actor.
Create an Attribute SpyCarPosX.Attribute.
Create an Attribute SpyCarPosY.Attribute.
Within spycar.Actor, create a timer(or better, a GStimer) that records every .5 seconds the X,Y location of Spycar.Actor.
Create another Actor, NPC.Actor.
Within NPC.Actor, add move fuctionality that moves(there are multiple options of controlling the movement, you might have to look into that further) to the above X,Y positions.
Using TShirtbooths Tutorial on Youtube, create a rule to check the distance between two actors.
Then create your if statement that states the following.
If the distance between NPC.Actor and SpyCar.Actor is Less than 10(example)
NPC.Actor RAMS SpyCar.Actor
Else
do nothing.
You could alternativly could constrain the X,Y positions to the attributes above, but it would be pretty much impossible to escape. Because the car would change direction the same second you do.
Sounds like a great project, Hope this Helps
Answers