Jump to content
  • Advertisement
Sign in to follow this  
Kinetic

Sight Trace

This topic is 4383 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

New member, still unsure about which forum to post this in but this one seemed appropriate enough. I've been able to make a good enough Java engine for 2d top-down shooter games, with workable collisions with obstacles, but one thing that's stumped me is how to make the bots that populate the corridors check to see if they can actually -see- the player, i know that the method includes tracing a ray from the bot to the player, if it hits an obstacle it terminates. Right, and from what i could come up with i have to check every point along a line. But to do that in this i'd be performing about 500 checks per trace, (thats like twice the compares for a single cycle). I KNOW there's a better way; but i can't think of it. I tried taking blocks of coordinates and checking ranges inside the block, but it still wasn't good enough. For reference, i'm running lag-less on a basic map on a 1.5ghz 128mb all integrated machine. I haven't big-O'd the exact stress yet, but you get the idea. Note that there's no Tile-based-ness of the game, it's completely free, in other words the only thing i work off is the screen size, 1024x768; all entities have x and y values. if i have to change this i will but hopefully i wont have to re-engineer it. Any help is WELL appreciated.

Share this post


Link to post
Share on other sites
Advertisement
virtually like entities, except without all the hassle of health, velocities, etc. simply a class with x/y coords and width/height values. plus a few other peripherals like the image to use and such.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kinetic
virtually like entities, except without all the hassle of health, velocities, etc. simply a class with x/y coords and width/height values. plus a few other peripherals like the image to use and such.
Ok, so basically we're talking about axis-aligned boxes?

If so, testing for the intersection between a line segment and an axis-aligned box in 2D can be done very efficiently using the separating axis test.

As for the broad phase, depending on how many obstacles there are it may be sufficient to brute-force it and test the segment against each obstacle in the world. If that doesn't work, you could first cull the obstacles against an AABB containing the segment. If more efficiency is needed, and the obstacles are similar in size, a uniform grid would probably be the next best option.

Now this is how I'd solve the problem in C or C++; I'm not familiar enough with the language to know if the same sort of solution would be practical or feasible in Java (I'm guessing it should be though).

Let me know if you need further info or clarification on any of the above.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!