Jump to content
  • 0
Phodex Games

Make NPC move away from player?

Question

Hey, I am currently working on my AI, and I wonder what would be a good way, to make my NPC hold a specific distance to the player. In my case I need it for my AI behavior when it is using range weapons. I think a nice idea is to let the AI find a random point, which keeps a few conditions like, 10 units away from player, not outside of the map, not inside another object. But how to realise that. I would be very thankful if you can give me ideas, examples, descriptions etc.

Share this post


Link to post

2 answers to this question

Recommended Posts

  • 0

You could do something hacky like this. Do this for like 10 or 20 points around the player using sin() and cos()  multiplied by the distance you want (10 in your example) from the player's global location. Use World:Pick() from that point to the player, this tell you if this point has line of sight to the player. If your level has walls then this will also tell you if you are on the map or not. If your level does not have walls you could do another World:Pick() from the point to the same point with a big -y value to see you are over an object. If your level is not flat this can get complicated, if there are no ceilings you could use World:Pick() with some big +y value to a big -y value to find the ground, then do the line of sight pick from that point to the player. You wouldn't want to run this every frame but it should work.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   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.

×
×
  • Create New...