Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

I'm struggling to implement this into an asteroid-like game that uses motion_add for movement based on image rotation/angle because the script's _mv_spd expects an integer but I add movement simultaneously to direction and speed. If I separate the values, then speed increases exponentially regardless of direction... but I only want +/- speed in the player object's direction of movement.


Any help would be greatly appreciated!

Ship Create

vardirection=direction;
varspeed=speed;

Ship Step Event

//Movement Script

movement_and_collision(vardirection,varspeed,obj_wall_base);

//Add movement in direction

if (keyboard_check(vk_left) or keyboard_check(ord("A")))
{
sprite_index = spr_shipa;
vardirection=image_angle+90;
varspeed+=1;

}

if (keyboard_check(vk_right) or keyboard_check(ord("D")))
{
sprite_index = spr_shipd;
vardirection=image_angle-90;
varspeed+=1;

}

if (keyboard_check(vk_up) or keyboard_check(ord("W")))
{
sprite_index = spr_shipw;
vardirection=image_angle;
varspeed+=1;

}

if (keyboard_check(vk_up) or keyboard_check(ord("W")))
{
sprite_index = spr_shipw;
vardirection=image_angle;
varspeed+=1;

}

I don't see motion add in here, but essentially what you want to do is keep track of your horizontal speed and vertical speed separately.  And then use point_direction(0,0,hsp, vsp) to turn that into a direction, and point_distance(0,0,hsp,vsp) to turn it into a speed to pass to the script. I also recommend not using image_angle, as this will also rotate your collision mask which could cause problems.  Create a new variable to handle the display of a rotated sprite and draw the sprite in the draw event using draw_sprite_ext() with this new variable substituted for image_angle.