[Kind of closed] "Line of sight"

This forum is currently in read-only mode.
  • I'm trying to make a game in which you have line of sight to objects Now there is really only one type of sprite object in the game except for the player's sprite which needs to be considered, but the line of sight behavior is just not working correctly. Even if it was, It kills the frame-rate.

    This is an example I made which uses the same system as I do in my larger application. In this example I try to work around the the line of sight behavior.

    The <font color=red>problem</font> still remains though. <font color=red>Any good Line of sight vision I can come up with is way to CPU-intensive to be efficient.</font>

    <font color=yellow>Cap File example</font>

    yourfilelink.com/get.php

  • Working on an alternative LOS system for you, I'll have it uploaded soon...

    Edit:The Line Of Sight behavior is pretty buggy for multiple instances of the same object it seems, so I only use it for my Player object. However, I have a cap here to show you how to do line of sight for the other objects.

    Get it here.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Man, that's brilliant. I would never have figured that out! Thank you very much for your help and for your time Jayjay. This will help me make my game a lot less CPU-demanding. <img src="smileys/smiley32.gif" border="0" align="middle" />

  • Man, that's brilliant. I would never have figured that out! Thank you very much for your help and for your time Jayjay. This will help me make my game a lot less CPU-demanding. <img src="smileys/smiley32.gif" border="0" align="middle" />

    No problem Nifl =] It came to me by surprise when I realised my game was ruined by the LOS behavior <img src="smileys/smiley17.gif" border="0" align="middle" />

    Glad to help though <img src="smileys/smiley4.gif" border="0" align="middle" />

  • Even if it was, It kills the frame-rate.

    This has been answered just a few weeks ago. There is a bug in the LOS behavior regarding objects with instances. The workaround is to use a family instead of the object itself (Just put the object into its own family).

  • > Even if it was, It kills the frame-rate.

    This has been answered just a few weeks ago. There is a bug in the LOS behavior regarding objects with instances. The workaround is to use a family instead of the object itself (Just put the object into its own family).

    Thanks for the response, but I tried that already. It doesn't work for me. I have 1 player object and hundreds (some times) of "non player objects". If I use Families, I can't get the LOS behaviour to work at all.

    I wan't to make objects obscure each other, so that the one in front of another is obscuring it. Just can't get it to work :(

    And JayJay, the system you made was very interesting and "kind of worked". It seamed however that once an object gained sight of me, it continued to be able to see me, even if I hid behind the "map". Also it became very laggy once i reached about 100 objects (Yeah I know, 100 objects is a lot, but that's the problem, the player needs to be able to interact with the world very well, therefore I can't just make static Background object, or sprites with no LOS).

    Well, I feel than I have complained a lot. Maybe there is no way to be able to measure if you can see objects (with one hundred of them) without lagging. <img src="smileys/smiley19.gif" border="0" align="middle" />

    Thanks anyway guys. For now I guess I'll have to live with the idea that Line of sight doesn't work.

  • I think there's something wrong. You might think too complicated, or you made an error in the events or whatever else. Of course, you have to optimize things, the more objects you need to control per tick. But in general, those behaviors aren't that slow.

    For example, this (admitted, very simple) cap hosts a player, some obstacles and 200 opponents, and the opponents try to chase the player sprite while they "see" it, and immediatly stop, as they don't "see" it.

    This runs with over 400 fps on an on-board-graphic chip, so I expect this to run at a few thousands on a middle class card.

    http://www.mediafire.com/file/mjdgo9y7l93ovnl/LOSspeedtest.cap

  • Just saw that you linked to your cap (hint: yellow on white = unreadable ;) )

    Didn't want to dl it at first, cause I hate those "wait x seconds before dl"-sites, but could convince myself to do so.

    A first look revealed why you have problems. You are demanding too much. Quick example:

    You order to loop with 360 iterations per tick for every key that is down. That's 720 iterations per tick, if two (e.g. left and up) are down. These loops create up to 1440 (!!) sight instances and you order each one of these 1440 instances to check against 623 OtherObjects instances. That's 897120 checks per tick. I think, that's no reason to complain, but more a reason to praise CC for its speed :D

    If I knew what you really intend to do, I'd propose something. But I'm not sure. Do you want to reveal more of the scene, as the player approaches the walls? But why are then instances placed over other instances drawing the same graphic at the same spot 2 times?

  • Thanks for taking time helping me. I downloaded your cap file and tested it. It worked (of course :] ) and that great. The problem isn't solved though. I may have been unclear in what I was trying to achieve. Ill try to explain better.

    I have 1 player object (Call it "PlayerSprite") which i need to test Line of sight to objects from and I have 1 object which acts as both walls and enemies (Call it "Wall&EnemySprite").

    I need to be able to test if the "Well&EnemySprite" can be seen by the player.

    Now this, you solved if I were to have another object blocking the vision but the problem is that I need to know:

    Is any "Wall&EnemySprite" blocking the line of sight to any other "wall&EnemySprite"?

    That is:

    What "Wall&EnemySprite"s can the "PlayerSprite" see, and what "Wall&EnemySprite is blocked by other "Wall&EnemySprite"s?.

    I don't know how well I explained it, but I really only have 2 "Active objects" in the game; a PlayerSprite and a sprite representing enemies AND obstacles. (And I need it that way, as walls need to change to enemies and vise verse in my game)

    I Also should say that its kind of grid-based. It's a large chess board so to speak, with each "wall&enemySprite" having a huge number of private variables defining them, Including Alive,Mechanical,Ethereal and Enchanted each together deciding if the object is capable of acting as a NPC or if its "Dead", acting as a wall...

    Again thanks for the help, I understand that I'm not representing an easy problem, and than the solution may be to hard (or nonexistent in construct). But I really don't need a Super solution, only a frame-rate over, say 20, as its turn-based. All I need is to be able to play the game on slower PCs with that sort of stable frame-rate. :/

  • tulamide

    Just curious, any reason why you used 'move at angle' for the player instead of a behavior?

  • Nifl

    You can't do it with the LOS behavior, can't test two instances of an object for LOS, pity. I've had similar problem while playing with a path movement. I think, you'll have to create your own LOS - haven't checked if you could use Jayjay's example for it.

  • This can be done with my cap Nifl, just have a private variable to say what mode the wall/enemy is in. Then only set the enemy to "NOLOS" when the object LOSCheck overlaps is in "WALL" mode.

    Edit: Just saw that you already have a "DEAD" state. Just use that variable to choose if the object blocks others or now.

    As for the lag with 100 objects, I'm not sure what's going on there, as I get over 200 fps with around 200 BadGuy objects while also running the debugger. Can I see the events you're using?

  • >tulamide

    Just curious, any reason why you used 'move at angle' for the player instead of a behavior?No particular reason. I'm just used to do it this way if I'm in a hurry. The cap was a quick&dirty product :)

    Now this, you solved if I were to have another object blocking the vision but the problem is that I need to know:

    Is any "Wall&EnemySprite" blocking the line of sight to any other "wall&EnemySprite"?

    That is:

    What "Wall&EnemySprite"s can the "PlayerSprite" see, and what "Wall&EnemySprite is blocked by other "Wall&EnemySprite"s?.

    I don't know how well I explained it, but I really only have 2 "Active objects" in the game; a PlayerSprite and a sprite representing enemies AND obstacles. (And I need it that way, as walls need to change to enemies and vise verse in my game)This is what I mean by "think too complicated".

    For every game there comes a time when you have to optimize your code/thoughts. Even the biggest game developers wouldn't be able to constantly check roughly 1 million times per tick without dramatically slowing down their game. So it is about tricking. Like in 3D games high poly models are exchanged by low poly ones when they are displayed far away.

    1) You don't need to test all instances. Limit the tests to the range that your player sprite will "see".

    2) Don't loop 360 times to get a full circle. Instead create one circle sprite and set it to the radius you want the player to be able to see. Select all blocks that overlap that sprite (Or use no object at all and select those blocks with math only). Now loop through those blocks and check with sample points every blocksize against the angle to the player sprite if there are other blocks in the way. If so, set it to invisible, else set it to visible.

    This should speed up a lot. I didn't have a look at JayJay's cap. Maybe it is exactly doing so. If not, I might do a cap, if I find the time.

  • Well, thanks for taking the time everyone, (Have been afk over 9/11). I greatly appreciate your thought about and knowledge into the subject. I'm going to create a secondary object to test for line of sight now. Lets see how that pans out. If it doesn't work, well then I'll probably deal with this at a later time. It is taking to much of my creation time at the moment. Thank again everyone :]

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)