1. Hey! Guest! The 31st GMC Jam will take place between Nov 16th, 12:00 UTC (Friday noon) and Nov 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 [Solved] How do I get the X and Y axis values from a direction value?

Discussion in 'Programming' started by 1nkFa1c0n, Nov 6, 2018.

  1. 1nkFa1c0n

    1nkFa1c0n Member

    Joined:
    Oct 2, 2018
    Posts:
    4
    Say I have a direction and that I want to get the x and y axis values from that. Similar to how I can get a direction from a gamepad with point_direction, is there anything I can use?
     
  2. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    508
    You can use lengthdir_x and lengthdir_y to get the x and y coordinates along a direction.
     
  3. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,262
    Something like this should work (assuming I didn't make a mistake and you modify it to fit how the rest of your code works):

    Code:
    
    var haxis = gamepad_axis_value(0, gp_axislh);
    var vaxis = gamepad_axis_value(0, gp_axislv);
    length = point_direction(0, 0, haxis, vaxis);
    angle = point_distance(0 ,0, haxis, vaxis);
    
    h_dist = lengthdir_x(length, angle);
    v_dist = lengthdir_y(length, angle);
    
    
     
  4. 1nkFa1c0n

    1nkFa1c0n Member

    Joined:
    Oct 2, 2018
    Posts:
    4

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice