• 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 How to recreate asteroids movement using GML alone?

G

gacl

Guest
I'm trying to avoid the use of 'speed'.

my whole ship movement script looks as follows:

if keyboard_check(vk_space)
{
obj_ship.x += cos(radtodeg(obj_ship.image_angle)) * 3;
obj_ship.y += sin(radtodeg(obj_ship.image_angle)) * 3;
}
if keyboard_check(vk_left)
{
obj_ship.image_angle += 3;
}
if keyboard_check(vk_right)
{
obj_ship.image_angle -= 3;
}

However, the ship is going all over the place, moving in any direction it wants to, seemingly randomly.

Can anyone tell me where I'm going wrong? I have the tip of my ship facing upwards, if it helps.
 

jo-thijs

Member
Hi and welcome to the GMC!

You've used radtodeg instead of degtorad, which is causing you trouble.
You'll probably also be interested in learning about the lengthdir_x and lengthdir_y functions.
 
you don't need degtorad because the trig functions have couterparts that take degrees as an argument
dcos, dsin. dsin should be negated in your calculations.

dcos
-dsin

or use lengthdir functions
 
B

bojack29

Guest
You can use dsin and dcos too

move in 45 degrees at length of 10
Code:
x += dcos(45) * 10;
y += -dsin(45) * 10;
 
I

icuurd12b42

Guest
sprite must point right

I dont know why you dont want to use speed. are you planning to do delta time movement?

step:
image_angle+=(keyboard_check(vk_left) - keyboard_check(vk_right)) * 3;
motion_add(image_angle,keyboard_check(vk_up)*.01);
friction = speed/20;

using your own system
create

spdx= 0;
spdy = 0;


step
image_angle+=(keyboard_check(vk_left) - keyboard_check(vk_right)) * 3;
var thrust = keyboard_check(vk_up)*.01;
var dx = dcos(image_angle) * thrust;
var dy = dsin(image_angle) * thrust;
spdx+=dx;
spdy+=dy;
spdx*=.99;
spdy*=.99;
x+=spdx;
y+=spdy;
 
G

GenjiBlackwood

Guest
sprite must point right

I dont know why you dont want to use speed. are you planning to do delta time movement?

step:
image_angle+=(keyboard_check(vk_left) - keyboard_check(vk_right)) * 3;
motion_add(image_angle,keyboard_check(vk_up)*.01);
friction = speed/20;

using your own system
create

spdx= 0;
spdy = 0;


step
image_angle+=(keyboard_check(vk_left) - keyboard_check(vk_right)) * 3;
var thrust = keyboard_check(vk_up)*.01;
var dx = dcos(image_angle) * thrust;
var dy = dsin(image_angle) * thrust;
spdx+=dx;
spdy+=dy;
spdx*=.99;
spdy*=.99;
x+=spdx;
y+=spdy;
I used this code, but my ship always goes in the opposite direction. Horizontally it works fine, but vertically it goes backwards. Like, when Im faced down, it goes up.
 
I

icuurd12b42

Guest
I used this code, but my ship always goes in the opposite direction. Horizontally it works fine, but vertically it goes backwards. Like, when Im faced down, it goes up.
try using -image_angle, if you are using the physics engine and the physics functions
 
Top