FlxTilemap.ray() diagonal line of sight problem

63 views
Skip to first unread message

Bojer Bojington

unread,
Nov 17, 2015, 10:19:53 PM11/17/15
to HaxeFlixel


I have an issue with enemies being able to see my player through walls arranged in a 45-degree angle.  I am using the checkEnemyVision() function provided in part VIII of the tutorial (_mWalls.ray(e.getMidpoint(), _player.getMidpoint())).  An example of what I am talking about is shown below, more info can be found here.

I have no idea how I would make the adjustment noted in the previous link.  I would figure you make it to the ray() function, but I can't really make sense of it.  I tried to just have additional rays to check an endpoint slightly offset from the enemy midpoint, but this did not work either.  I also found something that sounded related on this thread, but making that change to my FlxTilemap class did not make a difference.  I also tried copying the latest ray function from the FlxTilemap class in the dev branch over to my local copy, but that did not make a difference either.  What am I doing wrong and how can I resolve this issue?

Jeru Sanders

unread,
Nov 18, 2015, 3:13:00 PM11/18/15
to haxef...@googlegroups.com
Mm, this is kinda a problem intrinsic to raycasting, raycasting works by moving X distance in a certain direction and testing if there's a wall there, then just looping until a target is found, so this problem will occur.

You can however filter the raycast and check if it is actually valid, my idea would be something like this.

var step:Int = tileWidth;
var p:FlxPoint = FlxPoint.get();
var t:FlxPoint = FlxPoint.get();

p
.copyFrom(startPoint);


for (i in 0...Std.int(distance/step)) {
    p
.x += step * cos(angle);
    p
.y += step * sin(angle);
    t
.x = Math.round(p.x/tileWidth);
    t
.y = Math.round(p.y/tileHeight);

   
if (isTile(t.x + 1, t.y + 1) || isTile(t.x - 1, t.y - 1)) {
        trace
("The line probably only goes from $startPoint till $p");
       
break;
   
}
}
p
.put();
t
.put();

Obviously untest, but just step through the ray result and check if this instance has occurred.
And now that I think about it I'm surprised this is how FlxTilemap().ray() is implemented. There has to be a way to properly ray cast through a tilemap rather than this step and check method.

Bojer Bojington

unread,
Nov 19, 2015, 9:09:03 PM11/19/15
to haxef...@googlegroups.com
I see... that makes things clearer.  Thanks for the help, I will see what I can do :-)

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to a topic in the Google Groups "HaxeFlixel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/haxeflixel/eDqaXoYsOPY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to haxeflixel+...@googlegroups.com.
Visit this group at http://groups.google.com/group/haxeflixel.
To view this discussion on the web visit https://groups.google.com/d/msgid/haxeflixel/94d2511d-345a-4e18-900b-8726938fd497%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages