A
André Guilherme
Guest
Hi everyone!
I'm making a game using physics in which the player can draw a line that functions as the ground.
I can already draw the line, but I'm having trouble setting up its collision shape, and the ball never collides with it! (see image)
Here's my code!
When the player holds the left mouse button an obj_drawing_line is created.
Inside it, we have:
This object has no sprite, might that have something to do with it?
I don't know... so, help would be much appreciated!
Thank you in advance!
I'm making a game using physics in which the player can draw a line that functions as the ground.
I can already draw the line, but I'm having trouble setting up its collision shape, and the ball never collides with it! (see image)
Here's my code!
When the player holds the left mouse button an obj_drawing_line is created.
Inside it, we have:
paint = true; //while the player is painting this variable is true
lines_xy[0,0] = x; //in this array we'll save the drawing points 'x' in the column 0
lines_xy[0,1] = y; //and the drawing points 'y' in the column 1
line_nr = 0; //Number of total coordinates
fix[0] = noone;
my_fixture = noone;
checking_interval = 1; // The window of frames between coordinates check
lines_xy[0,0] = x; //in this array we'll save the drawing points 'x' in the column 0
lines_xy[0,1] = y; //and the drawing points 'y' in the column 1
line_nr = 0; //Number of total coordinates
fix[0] = noone;
my_fixture = noone;
checking_interval = 1; // The window of frames between coordinates check
//Check if player has stopped painting
if (obj_player.painting == false)
{
paint = false;
}
//If painting sets off the alarm according to the chosen interval of frames between checks
if (paint)
{
if (alarm[0] < 0)
{
alarm[0] = checking_interval;
}
}
if (obj_player.painting == false)
{
paint = false;
}
//If painting sets off the alarm according to the chosen interval of frames between checks
if (paint)
{
if (alarm[0] < 0)
{
alarm[0] = checking_interval;
}
}
//Add to the total coordinates value and save mouse 'x' and 'y' to the array
line_nr += 1;
lines_xy[line_nr,0] = mouse_x;
lines_xy[line_nr,1] = mouse_y;
//Create Fixture
physics_remove_fixture(id, my_fixture);
for (i=0; i < line_nr; i++)
{
fix = physics_fixture_create();
var xx = lines_xy[i,0];
var yy = lines_xy[i,1];
var xx2 = lines_xy[i+1,0];
var yy2 = lines_xy[i+1,1];
physics_fixture_set_edge_shape(fix, xx, yy, xx2, yy2);
physics_fixture_set_density(fix, 0);
physics_fixture_set_restitution(fix, 0.1);
physics_fixture_set_collision_group(fix, 0);
physics_fixture_set_linear_damping(fix, 0);
physics_fixture_set_angular_damping(fix, 0);
physics_fixture_set_friction(fix, 0.1);
physics_fixture_set_sensor(fix, false);
physics_fixture_set_awake(fix, true);
my_fixture = physics_fixture_bind(fix, id);
physics_fixture_delete(fix);
}
line_nr += 1;
lines_xy[line_nr,0] = mouse_x;
lines_xy[line_nr,1] = mouse_y;
//Create Fixture
physics_remove_fixture(id, my_fixture);
for (i=0; i < line_nr; i++)
{
fix = physics_fixture_create();
var xx = lines_xy[i,0];
var yy = lines_xy[i,1];
var xx2 = lines_xy[i+1,0];
var yy2 = lines_xy[i+1,1];
physics_fixture_set_edge_shape(fix, xx, yy, xx2, yy2);
physics_fixture_set_density(fix, 0);
physics_fixture_set_restitution(fix, 0.1);
physics_fixture_set_collision_group(fix, 0);
physics_fixture_set_linear_damping(fix, 0);
physics_fixture_set_angular_damping(fix, 0);
physics_fixture_set_friction(fix, 0.1);
physics_fixture_set_sensor(fix, false);
physics_fixture_set_awake(fix, true);
my_fixture = physics_fixture_bind(fix, id);
physics_fixture_delete(fix);
}
draw_set_color(c_black);
for (i = 0; i < array_height_2d(lines_xy); i++)
{
var xx = lines_xy[i,0];
var yy = lines_xy[i,1];
if (i+1 < array_height_2d(lines_xy))
{
var xx2 = lines_xy[i+1,0];
var yy2 = lines_xy[i+1,1];
draw_line(xx, yy, xx2, yy2);
}
}
for (i = 0; i < array_height_2d(lines_xy); i++)
{
var xx = lines_xy[i,0];
var yy = lines_xy[i,1];
if (i+1 < array_height_2d(lines_xy))
{
var xx2 = lines_xy[i+1,0];
var yy2 = lines_xy[i+1,1];
draw_line(xx, yy, xx2, yy2);
}
}
This object has no sprite, might that have something to do with it?
I don't know... so, help would be much appreciated!
Thank you in advance!
Attachments
-
77.3 KB Views: 8