LineOfSight issues

For questions about using Classic.

Post » Tue Jan 11, 2011 2:47 am

I'm using the LineOfSight behavior with a little top-down space adventure game. I want to use it along with a player-centered light and shadow-casting obstacle sprites to hide areas and objects that the player doesn't have a line-of-sight to.

It basically works, but I have two problems which I'd like to discuss:

1) Objects marked "Solid" never satisfy the "Has LOS to object" condition.
2) The "Has LOS to object" condition is only true when the player has direct line-of-sight to the center of the object.

Issue #1 can be worked around by using a secondary non-solid object at the same position as the solid object, which is then used to query visibility. Is there a better option, short of changing the behavior code?

Issue #2 seems to require a change to the behavior code to consider object width/height/radius. Or is there another option?

Thoughts?
B
2
G
3
Posts: 20
Reputation: 890

Post » Tue Jan 11, 2011 6:28 am

I think question 2 answered number 1. However if you were using the attribute to group your obstacles you can add those objects to a family, and use the family instead.
Keep in mind los does not add objects it detects to the selected objects list.

On number two:
The behavior works off of points, basically its the same as distance(x1,y1,x2,y2), only it can detect if something is in between those two points.

There is a work around that does not use the behavior. That being a detector sprite that you have scaled to the to the range of sight.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Tue Jan 11, 2011 12:55 pm

[quote="newt":1hot6jxe]However if you were using the attribute to group your obstacles you can add those objects to a family, and use the family instead.[/quote:1hot6jxe]

I'm using the "solid" attribute to block movement, not for any kind of grouping.

[quote="newt":1hot6jxe]Keep in mind los does not add objects it detects to the selected objects list.[/quote:1hot6jxe]

What are the "objects it detects" and the "selected objects list"? Are you saying that solid/obstacle objects are not in the list of objects to check for LOS?

[quote="newt":1hot6jxe]On number two:
The behavior works off of points, basically its the same as distance(x1,y1,x2,y2), only it can detect if something is in between those two points.[/quote:1hot6jxe]

I checked out the code and confirmed this. Thinking about it more, LOS logic that accounts for the size of the object is non-trivial. Nevertheless, it would still be really nice to have.

[quote="newt":1hot6jxe]There is a work around that does not use the behavior. That being a detector sprite that you have scaled to the to the range of sight.[/quote:1hot6jxe]

That would give me an easy arc and distance check, but it doesn't account for obstacles. I'd need to manually check if LOS to an object is blocked by another object.
B
2
G
3
Posts: 20
Reputation: 890

Post » Tue Jan 11, 2011 2:08 pm

[quote="MikeWyatt":vvz1phaj]What are the "objects it detects" and the "selected objects list"? Are you saying that solid/obstacle objects are not in the list of objects to check for LOS?[/quote:vvz1phaj]

It only checks for points so a large solid will do no good, since it only has 1 point...(Im guessing)
If it's not detecting solids you may have to add "obstacles" manually in your events.

[quote="MikeWyatt":vvz1phaj]That would give me an easy arc and distance check, but it doesn't account for obstacles. I'd need to manually check if LOS to an object is blocked by another object.[/quote:vvz1phaj]

Well distance(x1,y1,x2,y2) will give you that, but to get a line of sight you can take a rectangular object that can do collision detection, scaled to the range, and always pointing the same angle as the sprite, then have a collision event if the detector is overlapping an obstacle.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Jan 13, 2011 1:44 am

Thanks, Newt. I implemented your proposed solution and it works great. It's a bit slow because I'm creating a new "vision checker" sprite each frame for each object, so I may need to optimize that a bit later.
B
2
G
3
Posts: 20
Reputation: 890


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests