• 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!

GameMaker Lock Joystick Movement To One Angle

mar_cuz

Member
Hi All,

I'm trying to have my player move with the left stick of a game pad but back and forth on one angle only. So the angle can be:
Code:
 push_angle = point_direction(oGoal.x,oGoal.y, x,y);
I only want to move on that axis (push_angle) back and forth and the player cannot move from that angle, so if push left, the player will travel left, but on the specified angle. please see the attached picture demonstrating better. I only want to move back and forth along the push_angle.

my movement code:

Code:
var push_angle = point_direction(oGoalTarget.x,oGoalTarget.y,x,y);
var h_move = gamepad_axis_value(pad_num, gp_axislh);
var v_move = gamepad_axis_value(pad_num, gp_axislv);   
var pdir = point_direction(0, 0, h_move, v_move);

if (h_move != 0 && v_move !=0)  {
    speed = 2;
    direction = push_angle;
    }

please help.
thanks.
 

Attachments

obscene

Member
What's happening now?

Just at a glance, your code only allows you to move in one direction, so you need to reverse the direction (+180) or reverse the speed (*-1) depending on which way you press.
 

mar_cuz

Member
It doesn't even follow the angle in any direction at the moment.

I'll try reversing the angle by 180 and see what happens
 

mar_cuz

Member
What's happening now?

Just at a glance, your code only allows you to move in one direction, so you need to reverse the direction (+180) or reverse the speed (*-1) depending on which way you press.
I tried setting the direction to push_angle + 180 but even if I try -180 the player only moves towards the goal though now on the specific angle
 
Top