GMS 2 Drawing a line that then becomes solid for other physics objects

0TastyPie0

Member
I'm working on a marble run type game, were the player can draw lines for the marble to run down. I use fixtures to setup and draw the line, however other physics objects (such as the marble) seem unaffected by the line. They simply pass through it, when the line is suppose to act as a wall.

This is the code I used to bind the fixture to an instance, once the last point has been recorded:
Code:
// Create the Custom Wall
physics_fixture_set_density(fixture, 0);
var inst = instance_create_layer(lastX, lastY, "Instance_Walls", oWall);
with (inst) {
    // Copy Over Points for Drawing the Line
    var len = array_length_1d(other.pointsListX);
    array_copy(pointsListX, 0, other.pointsListX, 0, len);
    array_copy(pointsListY, 0, other.pointsListY, 0, len);
    points = other.points;
}
physics_fixture_bind(fixture, inst);
physics_fixture_delete(fixture);
"fixture" variable is were the fixture is located. "lastX" and "lastY" are the last coordinates recorded. I set density to 0 since I want the line to be static.

From what I've read in the manual, this is all i'm supposed to have to do for it to work. :confused:

I used this other forum post as reference to figure out fixtures (but the original poster didn't seem to have this issue):
https://forum.yoyogames.com/index.p...-line-on-mouse-move-that-have-a-physics.5776/
 

0TastyPie0

Member
I don't see where are you calling physics_fixture_add_point()?
I use physics_fixture_add_point in another location.
Code:
// Make More Connections
if (!point_in_circle(mouse_x, mouse_y, lastX, lastY, pointsDistanceBetween)) {
    physics_fixture_add_point(fixture, mouse_x, mouse_y);
    pointsListX[points] = mouse_x;
    pointsListY[points] = mouse_y;
    points++;
    lastX = mouse_x;
    lastY = mouse_y;
}
You have to get a certain distance away from the last coordinates recorded, for it to record the next.
 

Jezla

Member
I've been doing some experimenting on this, with just creating a simple straight line chain shape with two mouse clicks. I've found that the chain shape is not being created where I expect it to be, and that may be what your problem is. I was creating the chain shape instance at the first chain point (first mouse click), and when I turned physics drawing on, I found that the fixture was placed a good deal to the right and down from where I had placed the instance. I was able to correct this by creating the instance at 0,0; then the chain shapes appeared where they should (i.e. where I had clicked them.

My conclusion is that the manual may be in error regarding physics_fixture_add_point(). It states that the points for a polygon fixture are relative to the origin of the instance, but that chain fixtures are actual room coordinates, when it seems from my experience that the points for both fixture types are relative to the location of the instance.

In short, try creating your oWall instance at 0,0 and see what results you get. I'm also assuming that your fixture definition code is more complete than what you've posted, as I don't see a physics_fixture_create() call anywhere.
 

0TastyPie0

Member
In short, try creating your oWall instance at 0,0 and see what results you get. I'm also assuming that your fixture definition code is more complete than what you've posted, as I don't see a physics_fixture_create() call anywhere.
This worked! Thank you! :D And yes, my fixture definition code is more complete than what I posted (fixture creation is in the create event, which I didn't post).
 

Jezla

Member
Glad it worked! I just did a test in GM:S 1 and had the same issue, so I really do think the manual is in error. The function physics_fixture_add_point() uses coordinates relative to the instance, regardless whether it is a chain or polygon shape. That, or I'm doing something incorrectly!
 
Top