[Solved] Continually increase/decrease lengthdir y/x values

Hi All,

First post here and I need your expertise. I'm trying to make a 2d shooter following some spielding tutorials on youtube with modifications along the way. Currently i have the gun object using recoil with lengthdir x/y while also using mouse point direction for the image angle of the gun itself. Essentially I want to add a system where when a player holds down mb_left, the gun’s lengthdir xx/yy coordinates will continually change by 1 each frame, moving the gun upwards along an arcing path until it reaches 90 degrees pointing straight up.

I’ve tried doing this through an alarm and i can get it to shift by y degrees, but it’s not a continual increase, e.g. it just moves back and forth from the mouse point direction and mouse point direction + whatever y I entered.

Does that make any sense? Can someone point me in the right direction? I’m trying to learn GML as my first real programming so even if you can point me in the right direction it would definitely be a big help. Thanks

-SS
 

samspade

Member
It's tough to say without seeing any code, but my guess is you're directly setting the value that you're using for the guns angle every frame. So your code probably runs like this:
  • Value gets set
  • Value gets recoil added
  • Value gets set again (erasing the recoil added)
  • recoil added. . .
and so on.

One solution would be to track the recoil in a different value so you would have something like:

Code:
recoil += 1;
final_gun_angle = gun_angle + recoil;
Note that in the above system you would also need a way to decrease recoil when the player wasn't holding the the mouse, and a way to cap recoil.
 
I see what you are saying! I will try implementing this suggestion tonight (hopefully) if i get stuck i will throw in my code and maybe you can tell me where i'm going wrong. Thanks again for your suggestion samspade.
 
Samspade's suggestion worked like a charm - thank you again!

A follow-up question, if I may...

Is there a reliable way to move the mouse's y axis up by the same amount of pixels that my recoil variable 'rainbow' uses? Any thoughts? Thanks again you guys are really helping me out.

if mouse_check_button(mb_left)

{
rainbow += .08; //up recoil
image_angle += rainbow;
}

else

{
rainbow = 0; //resets
image_angle = point_direction(x, y, mouse_x, mouse_y);
}
 
Last edited:
Top