How to properly raycast?

So I’m trying to see if my character can detect the edge of a layer & / or edge with a raycast so I can stop the character from twitching when getting ready to fall off. how to do this?

Been looking into raycasting lately as well. I’ll probably look at and see what I can use.

Happy Thanksgiving.

@DaSoup : Happy Thanksgiving to you & yours as well! :slight_smile: This is a VERY interesting example I hadn’t come across, so thank you! :slight_smile: Please let me know your results on this post! :slight_smile:

@Thundros Found a better example:

Not sure this functions as an actual ray. Like it would hit the closest object first instead of just the first object in the group, so this might need more work. (child, index) {
    if (typeof child !== 'undefined') {
        // Raycasting Test
        recChild=new Phaser.Geom.Rectangle(child.body.left,, child.body.right-child.body.left,;
        this.boxChild ={ lineStyle: { width: 2, color: 0xaa0000}});
        if (Phaser.Geom.Intersects.LineToRectangle(this.lineRay, recChild)) {
            console.log("ray hit child: ";
}, this);
1 Like

For anyone still interested in raycasting, there’s a great plugin available now:

Thanks will check it out.