• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GML Help with shooting recoil problem please!

Edwin

Member
I have a variable "can_shoot" that equals to true if I can shoot and to false if not. I also have a variable "shoot_delay" that equals to time (steps) of alarm that makes "can_shoot" variable equal true.

So when I shoot I need to make my bullet object make a "recoil" with changing it's direction.
Code:
with (o_bullet) {
    direction += irandom_range(-shoot_delay, shoot_delay):
}
So it works but when I shooting and have a smaller value of "shoot_delay" variable recoil gets more weaker and weaker, but it's not what I want: I want to make it stronger!.

Video:
How can You see in this video, if "shoot_delay" = 1, then the recoil is smaller than if 'shoot_delay" = 15 or more.

Please help!
 

marasovec

Member
Oh I see. I guess your max shooting delay is 15 so try this
Code:
shoot_delay = 15 - shoot_delay;
direction += irandom_range(-shoot_delay, shoot_delay):
 

Edwin

Member
Oh I see. I guess your max shooting delay is 15 so try this
Code:
shoot_delay = 15 - shoot_delay;
direction += irandom_range(-shoot_delay, shoot_delay):
The problem isn't in it. You see, when I shoot and my shoot_delay is 15 or more, shoot recoil is big, but I want to make it small
 

marasovec

Member
I'm trying to understand.. You have a shoot recoil which depends on the shoot_delay but you want to make the recoil smaller but still depending on the delay?
 

Edwin

Member
I'm trying to understand.. You have a shoot recoil which depends on the shoot_delay but you want to make the recoil smaller but still depending on the delay?
I just need to make it negative. Like the less the shoot delay value then stronger the shoot recoil.
 
well I think what is happening here is every time you make a bullet your changing the direction of every bullet meaning they eventually even out near the middle of the random. Make sure your only refencing the bullet you create if that's the case by doing something along the lines of

new=instance_create(x,y,o_bullet)
new.direction+= irandom_range(-shoot_delay, shoot_delay):

Also its worth noting if that dosent help for everyone else I believe when he says recoil he means the bullets accuracy.
 

Edwin

Member
well I think what is happening here is every time you make a bullet your changing the direction of every bullet meaning they eventually even out near the middle of the random. Make sure your only refencing the bullet you create if that's the case by doing something along the lines of

new=instance_create(x,y,o_bullet)
new.direction+= irandom_range(-shoot_delay, shoot_delay):

Also its worth noting if that dosent help for everyone else I believe when he says recoil he means the bullets accuracy.
Look! When shoot_delay is equal to a small number, the recoil of the weapon also decreases, and I want the opposite - to increase.
 
As I mentioned before that's most likely caused by the fact that your changing all the bullets on the fields direction every time you make a bullet not just the new one created.
 
ok nevermind I see what your doing, as mentioned above best way is to just inverse it by using something like
accuracy=16-shoot delay
direction+=irandom_range(-acccuracy, accuracy):

this means theres a 30 direction spread if the can shoot is 1 and a 1 degree if the shooting speed is 15
 
Top