tproper Posted October 18, 2018 Share Posted October 18, 2018 I have a line with multiple points: // Loop through all points and draw each line segment var graphics = game.add.graphics(0, 0); for(var i = 1; i < line.length; i++){ var from_x = line[i-1][0]; // x var from_y = line[i-1][1]; // y var to_x = line[i][0]; // x var to_y = line[i][1]; // y // Draw segment graphics.lineStyle(5, 0xff0000); graphics.moveTo(from_x, from_y); graphics.lineTo(to_x, to_y); } I want to make a physics body out of this so that other bodies will collide with the shape of the line. How can I do this? Link to comment Share on other sites More sharing options...
mcofko Posted October 18, 2018 Share Posted October 18, 2018 Hi tproper, check this example here: https://phaser.io/examples/v2/arcade-physics/one-way-collision It should be pretty straightforward. Replace the sprite (Atari) object with your graphics (line) object. Link to comment Share on other sites More sharing options...
tproper Posted October 19, 2018 Author Share Posted October 19, 2018 I actually tried something along those lines. The problem with creating it that way is that the physics body created is a rectangle shape made around the diagonal line. I need the line to curve, based on the different segments. Thanks though. I have another way that is working okay now, but if you know how to make the physics body look just like the line, please let me know. I'm sure, if phaser has a way of doing it, then it would be more efficient than what I'm currently doing. Link to comment Share on other sites More sharing options...
Recommended Posts