Jump to content

Make NPC move away from player?


Phodex Games
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

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