Weapon isn't Working as Intended

I been working on a laser like weapon for my game and I got it to work. But for some strange reason the beam itself wont kill the enemy, I will have to get up close. The actual beam drawn just go through the enemy and doesn't take ant damage.


Step Event of Laser

GML:
x = obj_player.x;
y = obj_player.y;



    dir = point_direction(0, 0, gamepad_axis_value(0,gp_axislh), gamepad_axis_value(0,gp_axislv))
    dir = round(dir / 45) * 45// Snaps the Direction of the Weapon
    
var max_length = 900;
for ( i = 0; i < max_length; i++) {
    
xEnd = x + lengthdir_x(max_length,dir);   
yEnd = y + lengthdir_y(max_length,dir);
    
 length_laser = i;   
 
}



if(timer == 30) {
  instance_destroy();
}
timer++
Draw Event

GML:
draw_line(x,y,xEnd,yEnd);

for (j = 0; j < length_laser; j++)

{
draw_sprite_ext(spr_heatvision,1,x +lengthdir_x(j,dir), y + lengthdir_y(j,dir),1,1,dir,c_white,1 )   
}

Script for Laser Damage

GML:
function scr_heatvisiondamage(){

var laser =  instance_place(x,y,obj_laser)
        if(laser)
        {
        death_bullet = true
        instance_destroy(laser)
        hp--;
        flash = 3
        state = enemy.enemy_hit
    }

}function scr_heatvisiondamage(){

var laser =  instance_place(x,y,obj_laser)
        if(laser)
        {
        death_bullet = true
        instance_destroy(laser)
        hp--;
        flash = 3
        state = enemy.enemy_hit
    }

}
 

Nidoking

Member
The way you draw an instance has nothing to do with its bounding box. If you're using draw_sprite_ext to make it appear different from the way it would appear using draw_self, the instance_place call still treats it as if you were drawing it with draw_self. You'll have to find another way to calculate collision, or use the built-in variables to tell the laser how to draw itself rather than using a special draw call.

it should be "with(laser)" not "if(laser)"
Who ever heard of a laser losing hp?
 
If its a laser I'd suggest using collision line.
I put this into the step event, but it is still killing the enemy up close. I been following a tutorial on youtube, but I do have a script in which it reduced the hp of the enemy, but I want to know how I could apply it here.

GML:
x = obj_player.x;
y = obj_player.y;



    dir = point_direction(0, 0, gamepad_axis_value(0,gp_axislh), gamepad_axis_value(0,gp_axislv))
    dir = round(dir / 45) * 45// Snaps the Direction of the Weapon
    
var max_length = 900;
for ( i = 0; i < max_length; i++) {
    
xEnd = x + lengthdir_x(max_length,dir);   
yEnd = y + lengthdir_y(max_length,dir);
    
 length_laser = i;   
 
 if (collision_point(xEnd,yEnd,obj_wall,0,0)  ) {
 
 break;
 }
 
 
}

if (instance_exists(obj_grunt))
{
    var _list = ds_list_create();
    var hits = collision_line_list(x,y,xEnd,yEnd,obj_grunt,0,0,_list,0)
    
    if (hits > 0)
    {
        for (var k = 0; k < hits; ++k){
            
            _list[| k].hp = _list[| k].hp -1;
            
        }
    }
    ds_list_destroy(_list);
    
}
 

p6v

Member
Who ever heard of a laser losing hp?
I was reading quickly, hence my short comment on the post. all i saw was them naming a variable that creates an instance and then an if statement next to said variable. generally when you create a instance through a variable you use the with statement afterwards.
 
Top