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

Legacy GM image_angle vs direction

woods

Member
so i am working on a space shooter(asteroids style) the issue i am facing is dealing with facing and drift.

i want to be able to start moving in one direction and turn my ship and still have the "forward motion" until i hit forward...if that makes sense.

reducing friction simply allows me to slide farther... not exactly what i am looking for.

thoughts?

obj_player create event
Code:
/// initialize variables

speed = 0;
max_speed = 5;
min_speed = -3;
direction = 0;
image_angle = 0;
powerup_splitshot = false
friction = 0.01

obj_player step event
Code:
/// movement

if speed >= max_speed //max speed
    {
    speed = max_speed;
    }
if speed <= min_speed // max reverse speed
    {
    speed = min_speed;
    }
//controller - sticks

if gamepad_axis_value(0, gp_axislh) > 0.5 //right
    {
   direction -=2;
   image_angle = direction;
    }
if gamepad_axis_value(0, gp_axislh) < -0.5 //left
    {
    direction +=2;
    image_angle = direction;
    }
if gamepad_axis_value(0, gp_axislv) < -0.5 //forward
    {
    speed += 0.1;
    }
if gamepad_axis_value(0, gp_axislv) > 0.5 //reverse
    {
    speed -= 0.1;
    }
 

JackTurbo

Member
Ok so I'd suggest using a custom variable instead of direction, because direction is tied to your movement. Say facingDir. Your turning inputs will want to increase and decrease this and each frame you'll need to make image_angle = facingDir

Next your gonna want to split out the movement into the X and y components .

You'll need a thrust variable for acceleration.

Basically each frame that youre thrusting you'll want add a lengthdir_x(thrust, facingDir) to your xSpd and a lengthdir_y(thrust, facingDir) to your ySpd. Then at the end of the step code simply update your x/y coords with the x/ySpd variables like: x += xSpd; y+= ySpd;

That will get you the basics of space like movement.
 
Top