Jump to content

Run away!


Rick
 Share

Recommended Posts

So the controller has Follow() but I'm looking at run away functionality. I'm curious if there is a cool LE entity way (low math) to do this. At a high level I'm thinking a point could be found in the complete opposite direction of the thing the controller is running away from at a given distance and then I could call the controllers GoToPoint().

 

I'm sure this is some vector math here. Get the vector between the controller and the thing I want to run away from, and then get the complete opposite. Normalize it, then scale it to some distance and see what point that is. Is there a different way that people can think of?

Link to comment
Share on other sites

I've done the direction part in an amateur way before. I placed a temporary entity (pivot?) at the enemy's position and used Point to point it toward the player. You can then get the angle and add 180 to it to face it the opposite direction. Then use a little math (sin & cos) to get a position some distance away.

Link to comment
Share on other sites

I was actually doing that, but listening to you I was rotating and then moving forward but I should be able to cut a couple lines and just give a negative z value in the move. Thanks!

 

[edit]

Saved me 1 line of code, but every line counts :)

Link to comment
Share on other sites

Another way you could do it is to just subtract the positions and then calculate the new spot from there:

 

dx = enemy.x - player.x
dz = enemy.z - player.z
normalized_dx = dx/sqrt(dx^2+dz^2)
normalized_dx = dz/sqrt(dx^2+dz^2)
final_x = normalized_dx * distance + player.x
final_z = normalized_dz * distance + player.z

 

And then move the enemy to that position. This way, you wouldn't have to deal with pivots.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...