Page 1 of 1

Line of sight

PostPosted: Sat Jan 07, 2012 16:46
by sapier
on some ocassions you need to know if between to positions is a line of sight. Doing this in lua is possible but may have huge performance impact,


Line of sight patch (fixed 3)

hopfully I'll manage to get the right one linked in here soon

PostPosted: Sat Jan 07, 2012 17:25
by sfan5
Should be merged!

PostPosted: Sat Jan 07, 2012 23:50
by randomproof
Isn't line of sight done in the client, not the server?

Edit:

Oh, I looked at the patch, you are just looking to see if there are any nodes between two points. Don't you need to take into account transparent nodes, like glass? Also, you might need to double check that getNodeNoEx() will force load a map block if it is not already in memory. Most of the getnode functions will not do that. You get a null or CONTENT_IGNORE node.

PostPosted: Sun Jan 08, 2012 04:25
by sapier
no I'don't just look if there's a node i already had a discussion with celeron about what is best to look at ... my first implementation did use "sunlight_propagates" but celeron didn't like this as fences for example would be a los problem.

Using the light parameter was his suggestion and i do support it too.

I didn't know that getNodeNoEx() does have this effect but I don't think its bad too if asking for line of sight you do want to know if there's a line of sight. In regular case you won't have to load any blocks as all blocks between active entities and players will be already loaded.

Of course you may always ask "do i have a line of sight to something not within active area". I don't see any usecase for this atm ... if there really is none you might be right and we should avoid creating an additional error case. But of course this will have the effect that we do give wrong information in some cases telling there is no line of sight while there is one.

EDIT1: probably there is a line of sight check in client but only for player actions. There can't be a check if the acting object is a server active object e.g. a mob that need's to decide if it can se a player and therefor start an attack ... not like current dm's attacking player even if they can't see them

PostPosted: Mon Jan 09, 2012 15:50
by randomproof
Ok, that makes sense. I didn't know how you were using this function. Everything seems right.

PostPosted: Tue Jan 10, 2012 14:49
by jn

v3f has a normalize method. I think you could do something like (pos2-pos1).normalize() instead of implementing the normalization yourself.