[Kind of closed] "Line of sight"

For questions about using Classic.

Post » Thu Sep 08, 2011 6:23 pm

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 problem still remains though. Any good Line of sight vision I can come up with is way to CPU-intensive to be efficient.

Cap File example
http://www.yourfilelink.com/get.php?fid=711344Nifl2011-09-13 12:14:51
B
6
S
1
G
2
Posts: 18
Reputation: 711

Post » Thu Sep 08, 2011 9:24 pm

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.Jayjay2011-09-08 22:20:17
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Thu Sep 08, 2011 10:56 pm

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.
B
6
S
1
G
2
Posts: 18
Reputation: 711

Post » Fri Sep 09, 2011 1:36 am

[QUOTE=Nifl] 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. [/QUOTE]

No problem Nifl =] It came to me by surprise when I realised my game was ruined by the LOS behavior

Glad to help though Jayjay2011-09-09 01:36:38
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Fri Sep 09, 2011 3:43 am

[QUOTE=Nifl] Even if it was, It kills the frame-rate.[/QUOTE]
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).
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Sep 09, 2011 10:41 am

[QUOTE=tulamide] [QUOTE=Nifl] Even if it was, It kills the frame-rate.[/QUOTE]
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).[/QUOTE]

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.

Thanks anyway guys. For now I guess I'll have to live with the idea that Line of sight doesn't work.
B
6
S
1
G
2
Posts: 18
Reputation: 711

Post » Fri Sep 09, 2011 11:31 am

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
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Sep 09, 2011 12:03 pm

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?
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Sep 09, 2011 3:03 pm

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. :/
B
6
S
1
G
2
Posts: 18
Reputation: 711

Post » Fri Sep 09, 2011 3:14 pm

>tulamide
Just curious, any reason why you used 'move at angle' for the player instead of a behavior?
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests