- Home /
[Line of Sight] Please evaluate my approach
Hello, all. I'd really appreciate any critique to my approach before I go ahead and try to start implementing. I'm trying to make line of sight for an RTS environment. A unit should spot an other unit if two conditions are met:
The two units are within detection range
The two units have no obstacle between them
So two units within range but have a hill or building between them should not detect one another.
Every unit will have a large sphere collider to represent its maximum detection range. Upon collisionStay the collider will be added to an array of possible detected units and a raycast will be fired every frame toward the collider.
If the raycast hits, the target is deemed detected. Raycasts will continue to be fired to the target until it leaves the detection sphere and removed from the array of objects in detection range.
I'm afraid of performance issues due to the number of raycasts, however. If 10 units come into detection range of 10 enemy units, that would mean 100 raycasts are fired every frame. Is that an acceptable number of raycasts?
What about attaching an invisible collider in the shape of your line of sight. Attach the inisible collider to a camera mount or something, then if it hits with anything at all, do whatever you need to do in function OnTriggerStay (otherObject : Collider) { // something here... }
@$$anonymous$$elaiah I think thats is, from how I read it, basically what he is doing. Well except for the shape, he is using a sphere ins$$anonymous$$d.
@chris_taylor Ah, I didn't read the question properly. Oh well, his approach seems sensible to me.
Agreed, that's how I read the question too.
Alternative, why not just raycast every 0.1 to 0.2 seconds?
Lots of RTS question recently, so other people here are doing the $$anonymous$$iniLD44 7dRTS? :)
That many (or more) raycasts every 0.1-0.2 seconds wouldn't be too performance intensive?
What is this $$anonymous$$iniLD44 7dRTS? I've just been playing SupCom with my friends from the S$$anonymous$$m summer sale and got frustrated at its limitations, so I wanna make a better game to play with my friends.
Answer by chris_taylor · Jul 24, 2013 at 05:42 AM
I would use Rain{Indie} or at least look at how they do it, they also do raycasting. The best part is Rain{indie} is free and has a bunch of other features and the tornado twins use it in their FPS kit
Your answer
Follow this Question
Related Questions
Block OnMouse~ whith UI 0 Answers
problem with raycasts and imported mesh 0 Answers
How to render a lot of the same small objects 2 Answers