graycontrast Posted August 20, 2016 Share Posted August 20, 2016 I am looking to implement a line-of-sight targeting in a 2-D platformer where the player presses a 'ready gun' button, moment is disabled, and a list of hitable targets is made and you can cycle through the targets. Is there a way to use ray tracing or the pick command in a 2-D area that will stop at every non-target object? If I can get those results I can make an array of targets to cycle through them. What is a good way to start? Quote Link to comment Share on other sites More sharing options...
gamecreator Posted August 20, 2016 Share Posted August 20, 2016 If you're using 3D models despite the 2D interaction, pick is probably the way to go. Otherwise you may have to scour the internet for collision code. Box2D or the like might help you also. Quote Link to comment Share on other sites More sharing options...
graycontrast Posted August 20, 2016 Author Share Posted August 20, 2016 right, I am using 3-D models in a 2-D interaction. But doesn't Pick just stops at the first object in a cylinder? is there a way to do it in a 2-D area or will I have to use multiple pick commands in evenly-spaced angles? Quote Link to comment Share on other sites More sharing options...
nick.ace Posted August 20, 2016 Share Posted August 20, 2016 Actually, volumetric shadows (or lighting) does something like this by deforming meshes using vertex shaders. However, that's way too complicated for this. You'll want to avoid casting rays from the player. Evenly spaced angles will generate too many rays for regions where there's no target. Do the inverse instead. You can make some sort of box around the targets, and then pick from various intervals between the top and the bottom of the box. This will give you a decent estimate. Otherwise, there's an infinite number of rays you would need to check. Pick doesn't stop at the first object. Internally it generates a list of objects since it is calculated out of order. You'll have to use multiple picks no matter what. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted August 20, 2016 Share Posted August 20, 2016 But doesn't Pick just stops at the first object in a cylinder? is there a way to do it in a 2-D area or will I have to use multiple pick commands in evenly-spaced angles? Check the pick docs. You can set closest to true and it will always get the closest object, which is what you want. I would shoot a ray from gun to a few bone positions in your characters like head, feet, hands, etc. Say 9 or so rays per person. If any one of them hit, you have sight of the character and can shoot him. Even if this is a little on the slow side, since you said time stops while you aim, it should be fine. Edit: You can probably shoot rays to only one side of the person and be fine since this is a side-scroller, saving some rays. No need to do both hands, both feet, etc. In fact, you might be able to skip the arms/hands altogether, depending on what your characters are doing. Quote Link to comment Share on other sites More sharing options...
graycontrast Posted August 20, 2016 Author Share Posted August 20, 2016 So a good way to start is say have a pick from the top and bot of the character? That should be a cheap way to get LOS, I don't plan on having any narrow holes you can shoot through. Should I save that information as vertices in the bad guy script? and to be more efferent I don't want to have to check every bad guy (like ones behind the character or way way down the map), just the ones in a certain range. Is there a way to collect the objects in a certain range without iterating through all the entities in the world? 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.