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

GML Object Inertia/Drift non-image angle direction

Hello,

Making a top down space shooter and not using the physics engine in game maker studio 2.

I have movement code that is mostly nice and smooth for turning speeds / acceleration / deceleration figured out but when I release a direction key (key_up or key_down) and start rotating the sprite left and right the direction follows the sprite image angle and not the natural "inertia" or "momentum" of the object as I want for something that's just cut power the engines and drifts.

I'm using lengthdir_x and lengthdir_y as below. old_direction is me trying to store the image angle as a variable when the key_up or key_down key is released but unsure how to do this.. happy with another method if one can be suggested.. I'm sure its something simple just leaning GML currently..

if !key_up || !key_down & spd >= 0
{
x = x + lengthdir_x(spd, old_direction);
y = y + lengthdir_y(spd, old_direction);
}
 
thanks for the post link

I played with the motion_add function previously and didn't find it controllable. basically even with speed limit applied it just keeps adding to movement in the specified direction... infinitely..

e.g. you code below didn't limit the objects movement speed as it seems motion_add is independent of any variable that sets / changes a speed?

// Limit Speed to MAX Speed
if ( speed > max_speed )
{
speed = max_speed;
}

confirmed this as I have the values displayed as GUI so i can see them change as i input keys and my speed value does not change with motion_add.

so i come back to how do i store the image_angle value at a keyboard_check_release(key_up) / keyboard_check_release(key_down) or !key_down / !key_up
 
motion_add() affects the built-in variable speed. Are you using your own spd variable instead?

Either way, you need to keep track of the direction the spaceship is facing, independently of its momentum.

So there is the speed and direction vector the ship is moving in, and another, I call it "facing" which is altered when pressing left and right, and is also used to update the image_angle of the sprite.
 
yes i am using my own spd variable and also set it to spd = speed. thought that would counter/balance it.

i'll go back to your example and rework it...

I did start playing with the below and it's incredibly broken but at least its movement in a direction that isn't image angle...

if keyboard_check_released(key_up) || keyboard_check_released(key_down) & spd >= 0
{
var _x1 = lengthdir_x(spd, direction)
var _y1 = lengthdir_y(spd, direction)
var _pd = point_direction(x, y, _x1, _y1)
x = x - lengthdir_x(spd, _pd)
y = y - lengthdir_y(spd, _pd)
}
 
Top