Dr_Nomz
Member
I have a script that sends a signal to an object to tell it to update it's variable, and the object, if it collides with something, damages the thing it hit.
That's in my player object's draw event, it creates a line that if it collides, it activates a script:
This script uses collision line to check if there's an enemy or a wall near it, and if there's nothing, collision will be 1, so that if the object's hitbox hit's something, it damages it.
This is the projectile (or melee) object's code. If attack is lower than 1, it can't damage another enemy. If collision is lower than 0, it won't damage anything.
What I want it to do is check for a collision, and if there's an enemy closer to it than a wall, it'll damage it, but not if the enemy is behind a wall. However I want this all to take place during the frame it's happening, not the frame after or it won't work. Is there any way to fix this?
The issue is if the script finds a collision, the melee object won't update and damage the enemy (or not if there's a wall) until the NEXT frame.
Code:
scr_Melee_Collision(x+lengthdir_x(0,angle_1+90),y+lengthdir_y(0,angle_1+90),x+lengthdir_x(punch_length_1,angle_1),y+lengthdir_y(punch_length_1,angle_1))
Code:
var collide_close = scr_Collision_Line_First(argument0,argument1,argument2,argument3,par_Bullet_Collision,true,false);
if (instance_exists(collide_close)){
if debug_message_bullet_collision == true{
show_debug_message("I collided with something")
show_debug_message(object_get_name(collide_close.object_index))}
// if (instance_exists(collide_far)){show_debug_message("I collided with something")}
if collide_close.object_index == obj_Wall ||
object_is_ancestor(collide_close.object_index,obj_Wall){
with par_Melee{ collision = 0; }
instance_create(collide_close.x,collide_close.y,obj_Hit_Detector_1);
//instance_destroy(self);
exit;
}else
if collide_close.object_index == par_Enemy ||
object_is_ancestor(collide_close.object_index,par_Enemy){
//with(collide_close){ scr_Enemy_Damage(argument0); }
with par_Melee{ collision = 1; }
//instance_create(collide_close.x,collide_close.y,obj_Hit_Detector_2);
//instance_destroy(self);
exit;
}else{
with par_Melee{ collision = 1; }
}
}
Code:
//Create Event
attack = 1;
collision = 0;
//Step Event
var collision_enemy = instance_place(x,y,par_Enemy);
if collision_enemy && attack == 1 && collision == 1{
with collision_enemy{
instance_create(collision_enemy.x,collision_enemy.y,obj_Hit_Detector_2);
scr_Enemy_Damage(obj_Punch_1);
}
attack = 0;
}
What I want it to do is check for a collision, and if there's an enemy closer to it than a wall, it'll damage it, but not if the enemy is behind a wall. However I want this all to take place during the frame it's happening, not the frame after or it won't work. Is there any way to fix this?
The issue is if the script finds a collision, the melee object won't update and damage the enemy (or not if there's a wall) until the NEXT frame.