• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker collision acting funny

L

Lorp

Guest
GM2
Windows 10
within obj_player step event
solid off
physics off
no collision event
total newbie

I'm playing with collisions for a top down tank game and came up with this bit of code. It draws a box with hit lines and feelers in the corners.

I'm wondering why it works on the right side but not the left?
can this work?

I had tried:
a point array on corners and midpoints where I used every collision check command;
storing the hit events in a list and cycling through the list separately.
the results differ slightly but this one comes closest to working.

//rotatable collision box.

for (i = 0; i<4; i++){
var x1 = x+lengthdir_x(46,direction +45 +(i*90));
var y1 = y+lengthdir_y(46,direction +45 +(i*90));
var x2 = x+lengthdir_x(46,direction +45 +90 +(i*90));
var y2 = y+lengthdir_y(46,direction +45 +90 +(i*90));
var hit_line = collision_line(x1, y1, x2,y2, all,false, true);

var x2 = x1+lengthdir_x(5,direction +45 +(i*90));
var y2 = y1+lengthdir_y(5,direction +45 +(i*90));
var hl_corner = collision_line(x1, y1, x2,y2, all,false, true);

if(hit_line != noone or hl_corner != noone){

//bounce effect
speed = speed*-1;
}
}

here is a draw event code to show what's happening
draw_self();
for (i = 0; i<4; i++){
var x1 = x+lengthdir_x(46,image_angle +45 +(i*90));
var y1 = y+lengthdir_y(46,image_angle +45 +(i*90));
var x2 = x+lengthdir_x(46,image_angle +45 +90 +(i*90));
var y2 = y+lengthdir_y(46,image_angle +45 +90 +(i*90));
draw_line_color(x1, y1, x2,y2, c_red, c_red);

var x2 = x1+lengthdir_x(5,image_angle +45 +(i*90));
var y2 = y1+lengthdir_y(5,image_angle +45 +(i*90));
draw_line_color(x1, y1, x2,y2, c_red, c_red);
}
 
Last edited by a moderator:
Top