Rick Posted July 29, 2016 Share Posted July 29, 2016 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? Quote Link to comment Share on other sites More sharing options...
gamecreator Posted July 29, 2016 Share Posted July 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted July 29, 2016 Author Share Posted July 29, 2016 It's sort of messy and more code than I'm guessing is needed but it does the trick. Thanks for the idea! Quote Link to comment Share on other sites More sharing options...
gamecreator Posted July 29, 2016 Share Posted July 29, 2016 Just thought of this: you don't really even need the +180 or the sin/cos math. Once you have the Pivot pointing toward the player, you can just use Move on it back some distance and get its position. No math at all! Quote Link to comment Share on other sites More sharing options...
Rick Posted July 29, 2016 Author Share Posted July 29, 2016 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 Quote Link to comment Share on other sites More sharing options...
nick.ace Posted July 29, 2016 Share Posted July 29, 2016 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. 1 Quote Link to comment Share on other sites More sharing options...
Rick Posted July 29, 2016 Author Share Posted July 29, 2016 That's much less code! I'll check that out. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.