• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Mirroring keyboard controlled crosshair when sprite turns. Help needed!

P

Pendy

Guest
So I have a platformer game project in mind that has a grappling hook system. I have made a "gun" and a crosshair that moves up and down. The Issue is I would like to have the maximum angle of the crosshair to 90 and 270. So that you can't aim behind yourself. Also when you turn around the crosshair would basically flip too.
I am very new to game maker and programming so proper explanations would be appreciated.
If my explanation didn't help. basically like in Worms games.

Guns code:
GML:
x = o_player.x
y = o_player.y +1.5

image_angle = point_direction(x,y,o_crosshair.x,o_crosshair.y);
Crosshair Create Event:
GML:
Orbit = 20; //Orbit distance
Angle = 0; //Angle set
Speed = 3; //Orbital speed
Crosshair Step Event:
GML:
//Orbital motion
if (keyboard_check(ord("W"))){
    Angle += Speed //Orbit Counterclockwise
    if(Angle > 360) Angle -=360; //keep angle below 360
}
if (keyboard_check(ord("S"))){
    Angle -= Speed //Orbit Clockwise
    if(Angle < 0) Angle +=360; //keep angle below 360
}

//Update position
x = lengthdir_x(Orbit,Angle) + o_gun.x
y = lengthdir_y(Orbit, Angle) + o_gun.y
Thank you in advance! And if you have any questions please ask away!
 
Last edited by a moderator:

kburkhart84

Firehammer Games
I would add code to the crosshair object. Basically, if the X is less than the player/gun's x, do image_xscale = -1; which keeps the size but flips the direction.
 
P

Pendy

Guest
I would add code to the crosshair object. Basically, if the X is less than the player/gun's x, do image_xscale = -1; which keeps the size but flips the direction.
Sadly I didn't get it to work. I think the problem with trying to use O_gun.x is that the guns image angle is pointing towards the crosshair. I tried using o_player.x but it still didn't work. Im pretty new to making games so Im probably missing some logic that could be used here. If you have time would you mind taking a look at my project and help me figure this out?
 
Last edited by a moderator:
Top