Hey! Follow me
by Tyler Slabinski · in Technical Issues · 12/14/2007 (5:30 pm) · 7 replies
I will be putting summoning monsters in my game. I have a question though, how do I get these guys to follow me? I was thinking of doing something gets the player's position data and taking something like:
Monster.setMoveDestination(VectorAdd(LocalClientConnection.player.getPosition(), "5 0 0")); Monster.setRotation(LocalClientConnection.player.getRotation());I neeed 2 things, I need to have the AI look at the same direction as me, but the setRotation doesn't seem to work. I also need it so that the AI realizes that I moved, so it will move too.
#2
This was from the aiGuard resource. If you do a search of the forum and resources, someone made a following ai.
12/15/2007 (6:52 pm)
You have to get your players position and set the AI to the same.//Gets the range to target - rtt %rtt=vectorDist(%obj.getposition(), %tgt.player.getposition());
This was from the aiGuard resource. If you do a search of the forum and resources, someone made a following ai.
#3
12/15/2007 (9:02 pm)
...I thought it meant like follow a marker. Ok, thx!
#4
Instead of constantly trying to run to the center of the player (which he can never get to because the player's collision box is stopping him), this code will make the AI run for a point 2 meters away from the player. Here:
O = monster
- = movement
# = player
*Running to the middle of the player*
O---------------------------#
*Giving the player some room*
O------------------------- #
For the look-where-the-player-looks part, it uses some vectoring to figure out which direction the player is looking and tells the ai player to do the same. Instead of getRotation(), using this will also tell the ai to match the vertical aim of the player.
Give it a try, post back if there are any problems.
12/16/2007 (10:49 am)
// Follow calculations %tgtPos = LocalClientConnection.player.getPosition(); %monsterPos = Monster.getPosition(); %vectorToTgt = VectorSub(%tgtPos,%monsterPos); %distToTgt = VectorLen(%vectorToTgt); %vectorToTgt = VectorNormalize(%vectorToTgt); %ptTwoMetersBack = VectorScale(%vectorToTgt, %distToTgt - 2); %movePos = VectorAdd(%ptTwoMetersBack, %monsterPos); // Look calculations %tgt = LocalClientConnection.player; %tgtEyePos = %tgt.getEyePoint(); %tgtEyeVec = VectorNormalize(%tgt.getEyeVector(); %scaledVec = VectorScale(%tgtEyeVec,300); // 300 meters in front of %tgt's eye %whereToLook = VectorAdd(%scaledVec,%tgtEyePos); Monster.setMoveDestination(%movePos); Monster.setAimLocation(%whereToLook);
Instead of constantly trying to run to the center of the player (which he can never get to because the player's collision box is stopping him), this code will make the AI run for a point 2 meters away from the player. Here:
O = monster
- = movement
# = player
*Running to the middle of the player*
O---------------------------#
*Giving the player some room*
O------------------------- #
For the look-where-the-player-looks part, it uses some vectoring to figure out which direction the player is looking and tells the ai player to do the same. Instead of getRotation(), using this will also tell the ai to match the vertical aim of the player.
Give it a try, post back if there are any problems.
#5
12/16/2007 (4:06 pm)
So, that basically makes him target me, run foward, and stop when he is close?
#6
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6673
Robert
12/17/2007 (4:19 am)
Details....http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6673
Robert
#7
12/26/2007 (2:59 am)
@Tyler: Yes, that's pretty much what I was trying to say, just couldn't find the words for it. This won't make him target you, but instead look the direction you are based on a scaled eye vector
Torque Owner Tyler Slabinski