Drag And Drop Moving tank at an angle

Discussion in 'Programming' started by Remeuf, Aug 11, 2019.

  1. Remeuf

    Remeuf Member

    Aug 11, 2019

    First of all, excuse my English (I have difficulties to follow the tutorials in English).
    I am in beginner DnD mode.
    My problem :

    I have a parent object (tank) that pivots on itself with the right and left keyboard keys. This object has an angle.
    I would like him now to advance (touch up) but keep his angle (he must advance in his angle = the front of the vehicle must always be in the direction of his direction - he is not a crab; )).

    N.B: The parent object has another child object. A turret. The turret pivots by following the mouse cursor (this part works well).

    thank you very much for your answer
  2. GMWolf

    GMWolf aka fel666

    Jun 21, 2016
    you can use the 'direction' and 'speed' variables.
    'direction' will set the direction of movement.
    'speed' will set the speed at which you move in 'direction'.
  3. Remeuf

    Remeuf Member

    Aug 11, 2019
    Thank you for your answer Wolf
    It does not work unfortunately.
    I also tried the lengthdir function for x and y:
    x = lengthdir_x (variable, angle_image);
    No result, my tank always goes ahead anyhow or not at all.
    I may go through fixed moves with sprite changes;)
  4. Toque

    Toque Member

    May 25, 2017
    Cosmonaut did a tutorial space rocks. She covers rotating and moving in that pointed direction. That might help. It might learn a few other things too.
  5. Remeuf

    Remeuf Member

    Aug 11, 2019
    I solved my problem in GML. It's simple and it works great. Here is the code for those who might be interested :

    var avance;
    avance = keyboard_check(vk_up);
    if (avance)
    x += lengthdir_x(4,image_angle+90);
    y += lengthdir_y(4,image_angle+90);

    Thanks Toque too ;)

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