T
Trontastic
Guest
Hello, first off I'd like to thank you all for fueling such a great community, I've learned a lot just by reading through the available threads here. However I'm still having some trouble with a concept. I'm working on a prototype for a top down shooter, in the shooter I intend to have multiple items and guns for the player to use. The issue I'm facing is that I cannot seem to get the gun to attach and rotate around the player object on a fixed point without it rotating itself. I've uploaded a couple of images of what I'm trying to achieve.
I initially had the draw event for the gun in the player object but I've realized that this will not work when it comes to adding new weapons later, so I've been attempting to have the gun draw itself at this point near the player. Here is the code I've tried to get working.
STEP
if (instance_exists(obj_player)) {
x = attached.x + lengthdir_x(offsetDist, offsetDir + attached.image_angle);
y = attached.y + lengthdir_y(offsetDist, offsetDir + attached.image_angle);
image_angle = offsetDir + obj_player.image_angle + initialAngle;
}
Originally I had the gun being draw by the player object with
DRAW
draw_sprite_ext(spr_gun,0,(x + lengthdir_x(48, image_angle) - lengthdir_y(48, image_angle)),(y + lengthdir_y(48, image_angle) + lengthdir_x(48, image_angle)),.4,.4,image_angle,c_white,1);
But realized that this would pose problems later even if I got the gun to rotate properly. So I'm looking for any input on the best way to achieve this goal.
I tried a similar draw event within the gun object itself but this didn't work. I've read some topics on this subject but none came with visual aids to reference what was actually being accomplished and the math seems to be a bit more than I can get my head around at this time. I get the concepts but I can't seem to apply them properly.
Any assistance would be greatly appreciated.
I initially had the draw event for the gun in the player object but I've realized that this will not work when it comes to adding new weapons later, so I've been attempting to have the gun draw itself at this point near the player. Here is the code I've tried to get working.
STEP
if (instance_exists(obj_player)) {
x = attached.x + lengthdir_x(offsetDist, offsetDir + attached.image_angle);
y = attached.y + lengthdir_y(offsetDist, offsetDir + attached.image_angle);
image_angle = offsetDir + obj_player.image_angle + initialAngle;
}
Originally I had the gun being draw by the player object with
DRAW
draw_sprite_ext(spr_gun,0,(x + lengthdir_x(48, image_angle) - lengthdir_y(48, image_angle)),(y + lengthdir_y(48, image_angle) + lengthdir_x(48, image_angle)),.4,.4,image_angle,c_white,1);
But realized that this would pose problems later even if I got the gun to rotate properly. So I'm looking for any input on the best way to achieve this goal.
I tried a similar draw event within the gun object itself but this didn't work. I've read some topics on this subject but none came with visual aids to reference what was actually being accomplished and the math seems to be a bit more than I can get my head around at this time. I get the concepts but I can't seem to apply them properly.
Any assistance would be greatly appreciated.