1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Top Down Sidestep

Discussion in 'Programming' started by Bulldrome, Feb 15, 2020 at 12:40 AM.

  1. Bulldrome

    Bulldrome Member

    Joined:
    May 31, 2019
    Posts:
    16
    Hello Everyone,

    I'm currently working on a top down spaceship arena game whos basic gameplay plays like Asteroids except each ship has specific moves. I'd like one of the ships to have a quick sidestep in order to dodge to the left of the right without having to turn the ship.
    I've been experimenting for a bit but can't seem to wrap my head around getting this to work. I've gotten the ships other moves to work but shifting the ship sideways depending on its angle is throwing me off.

    If anyone can offer some advice/tip it'd be greatly appreciated
     

    Attached Files:

  2. devKathy

    devKathy Member

    Joined:
    Dec 31, 2019
    Posts:
    33
    Well let's see...

    You're using motion_add so I'm going to guess that you're using some simple physics a bit here...

    In order to "sidestep" we'd have to find the right direction to go in. Try using the motion_add, offsetting the original image_angle by subtracting or adding 90 degrees. Probably add a substantial amount of friction to keep the "sidestep" short, I would imagine.

    That's my first thought, don't feel like there's quite enough context yet...
     
    Last edited: Feb 15, 2020 at 1:54 AM
  3. Niels

    Niels Member

    Joined:
    Jun 22, 2016
    Posts:
    831
    Sidestep is basically just a forward movement but with its 90 degrees added to its direction
     
  4. Bulldrome

    Bulldrome Member

    Joined:
    May 31, 2019
    Posts:
    16
    I understand I could shift the angle 90 degrees quickly, do the sidestep and then snap it back to it's original angle. But what should I do if I want the object to keep it's original angle while doing the sidestep?
     
  5. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,144
    I wouldn't use motion_add for this. Use the lengthdir_x/y functions and simply add/subtract in the direction of movement for the sidestep based on the image_angle. For example:
    Code:
    if keyboard_check(ord("X"))
    
    {
    x += lengthdir_x(1, image_angle + 90);
    y += lengthdir_y(1, image_angle + 90);
    }
    Then do the same for the right sidestep only subtracting 90 from the image angle. This way it won't influence the base speed and direction but will still do a "strafe" move when pressed.
     

Share This Page