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);
}
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: