Papa Doge
Member
Hello,
I'm playing around with some code to test different ways of finding the nearest collision using the collision_line function and I've created something that does what I want it to do but seems to crash the game pretty regularly.
I'm down to trash this whole concept and try something different but this is the closest I've gotten to my goal...
Goal = Click to draw a line from the player to the nearest surface then create a "sticky bullet" that instantly appears on the nearest surface.
Here's what I have in the player's "shooting" section...
What I'm doing is drawing a 1 pixel line to start and then adding to the length of the line while there is no collision.
I don't have the bullet layer, sprite, and all that other stuff set up yet so I'm debugging with a draw event that places a red circle where the "sticky bullet" will spawn.
Here's my debugging draw events...
----------
I suspect my use of a while loop is what's causing the crashing issue. I want the "sticky bullet" to appear instantly so I need this nearest surface calculation to happen in a single step.
I'm playing around with some code to test different ways of finding the nearest collision using the collision_line function and I've created something that does what I want it to do but seems to crash the game pretty regularly.
I'm down to trash this whole concept and try something different but this is the closest I've gotten to my goal...
Goal = Click to draw a line from the player to the nearest surface then create a "sticky bullet" that instantly appears on the nearest surface.
Here's what I have in the player's "shooting" section...
Code:
// THROW
if (key_throw) {
throwAngle = point_direction(x,y,mouse_x,mouse_y);
var travelDistance = 1;
throwX = x + lengthdir_x(32,throwAngle);
throwY = y + lengthdir_y(32,throwAngle);
targetX = x + lengthdir_x(travelDistance,throwAngle);
targetY = y + lengthdir_y(travelDistance,throwAngle);
while (!collision_line(throwX,throwY,targetX,targetY,par_obj_collisions,false,true)) {
show_debug_message("I'm hitting a wall here...");
targetX = x + lengthdir_x(travelDistance,throwAngle);
targetY = y + lengthdir_y(travelDistance,throwAngle);
travelDistance++;
}
show_debug_message("Free as a bird...");
}
I don't have the bullet layer, sprite, and all that other stuff set up yet so I'm debugging with a draw event that places a red circle where the "sticky bullet" will spawn.
Here's my debugging draw events...
Code:
draw_line_color(throwX,throwY,targetX,targetY,c_red,c_yellow);
draw_circle_color(targetX,targetY,8,c_red,c_red,true);
I suspect my use of a while loop is what's causing the crashing issue. I want the "sticky bullet" to appear instantly so I need this nearest surface calculation to happen in a single step.