S
Sarena
Guest
I created a character that uses a gun weapon, and whenever you right-click, it shoots a bullet projectile towards the position that you clicked in. I created it in a similar fashion to how I made the player move to a spot you click by left-clicking.
The system almost works completely how I want it to, but sometimes when I am shooting, the bullet object will stop on the wall and not disappear like it is supposed to.
Here's the code for my objPlayer's Step Event (involving the gun):
For the objProjectile, I added the following code to a Collision with objWall (and objGoalWeapon) Events:
The projectile seems to only get stuck when I click on the wall itself. My guess is that it has something to do with the path not being completed, so it might need an action for destroying itself if the path it is interrupted and unable to complete, but I'm not sure how to go about setting that up.
The system almost works completely how I want it to, but sometimes when I am shooting, the bullet object will stop on the wall and not disappear like it is supposed to.
Here's the code for my objPlayer's Step Event (involving the gun):
Code:
// Assign Variable
attack_input = mouse_check_button_pressed(mb_right);
// If Expression
if(attack_input)
{
// Assign Variable
firing_delay = firing_delay - 1;
// If Expression
if((mouse_check_button(mb_right)) and firing_delay < 0)
{
// Assign Variable
firing_delay = 1;
recoil = 4;
// Apply To
with(instance_create_layer(x, y, "Projectile", objProjectile)) {
// If Instance Exists
var l624DA0FF_0 = false;
l624DA0FF_0 = instance_exists(objGoalWeapon);
if(l624DA0FF_0)
{
// Destroy Instance
with(objGoalWeapon) instance_destroy();
}
// Create Instance
instance_create_layer(mouse_x, mouse_y, "Instances", objGoalWeapon);
// Assign Variable
PathWeapon = path_add();
// Assign Variable
direction = PathWeapon;
// Function Call
mp_linear_path(PathWeapon,objGoalWeapon.x, objGoalWeapon.y, 20, false);
// Start Following Path
path_start(PathWeapon, 20, path_action_stop, true);
// Set Speed
speed = 25;
// Set Direction Variable
direction = other.image_angle + random_range(-3, 3);
// Set Instance Rotation
image_angle += direction;
}
// Assign Variable
recoil = max(0,recoil - 1);
// Jump To Point
x = x - lengthdir_x(recoil, image_angle);
y = y - lengthdir_y(recoil, image_angle);
}
}
Code:
// Destroy Instance
with(objGoal) instance_destroy();
// Destroy Instance
instance_destroy();