Jump to content

Creating a physics object for a diagonal line


tproper
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...