T
Treecase86
Guest
Hey! In my game, I want my character to steadily increase in speed the longer you hold the movement key, currently, I'm using code that is quite long, and it doesn't work all that well. Can you please improve upon it? 'objSolid' is the ground. I don't have a running animation yet, either.
In a create event:
In a step event:
In a collision event:
In a create event:
Code:
acc=0.1;
global.vel=0;
maxSpeed=9;
ground=true
Code:
if keyboard_check(vk_left) && !place_meeting(x+(abs(global.vel)*-1)-1, y, objSolid)
{
global.vel -= acc * 2;
image_xscale = -1;
}
if keyboard_check(vk_right) && !place_meeting(x+abs(global.vel)+1, y, objSolid)
{
global.vel += acc * 1;
image_xscale = 1;
}if (global.vel > 0 && place_meeting(x+abs(global.vel)+1, y, objSolid)) or (global.vel < 0 && place_meeting(x+(abs(global.vel)*-1)-1, y, objSolid))
global.vel = 0;
//Speed limit
if global.vel > maxSpeed
global.vel = maxSpeed;
else if global.vel < -maxSpeed
global.vel = -maxSpeed;
if global.vel > -acc && global.vel < acc
global.vel = 0;
x +=global.vel//Gravity
if place_meeting(x, y+vspeed+1, objSolid)
{
ground = true;
gravity = 0;
}
else
{
ground = false;
gravity = 0.25;
if vspeed > 8
vspeed = 8;
}//Handle sprites
if ground == true
{
if global.vel == 0
sprite_index = playerR;
else if global.vel > -8 && global.vel < 8
sprite_index = playerR;
else
sprite_index = playerR;
image_speed = abs(global.vel / 20);
}
Code:
move_contact_solid(direction,12);
vspeed=0;
Last edited by a moderator: