Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / keeping NPCs from going out of bounds

Author
Message
jaccar09
13
Years of Service
User Offline
Joined: 27th Apr 2011
Location:
Posted: 2nd Jun 2011 11:35
hi, i'm trying to make a game where NPCs roam aimlessly in the playing area until an enemy is within its range. right now i'm trying to prevent them from going out of bounds and that's where i'm stumped. i already have a walking and turning controller for them, i'll put them after the code that i need help with, which is this:



this is the turning and walking controller:


i have no problems with the walking and turning controller, except that it lets the NPCs go out of the playing area. here's a legend on what the various variables mean:

OutOfBounds(x#,z#) = this function checks if the point is out of bounds
NPCdata#(x,2) = walking controller for the current NPC
NPCdata#(x,7) = angle of the current NPC
NPCdata#(x,8) = turning controller for the current NPC
NPCdata#(x,9) = x position of target
NPCdata#(x,10) = z position of target

NPCdata# is an array. i use 5 NPCs and control them with the values stored in the array.

in the first code, if the current position will go out of bounds, it will try to find the how far from the horizontal is the current angle in. then it adds twice of the result to the original angle and makes it walk. it should look like it bounced off the edge of the playing area but the NPCs just go straight through.

what should i do? i'm really out of ideas
Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 22nd Jun 2011 20:35
when I made a RTS game, i just put a function which check if object which moved is still in map area, if his coordinates are less than 0 or more than maps boundary, i place it at 0 or boundary coordinate.

If you specify what kind of map you have (square or some kind a labyrinth), it would be easier to help.

Another idea is to check collision and if NPC collides with other object make it turn in a random angle.
You would create a invisible limb in front of your NPC object, and check collision.

Here are some nice steering solutions (OpenSteer project):
http://www.red3d.com/cwr/steer/Obstacle.html
http://www.red3d.com/cwr/steer/Containment.html

Tell me what ideas you have yourself, or if liked 1 of mine. Can try explain them in detail

Join The dark Side! We have cookies

Login to post a reply

Server time is: 2024-11-27 21:49:45
Your offset time is: 2024-11-27 21:49:45