K
knru
Guest
I'm new to GameMaker and have very little experience on coding in general. English is not my first language, but I hope you can understand what I'm after.
So, I want a parallex background that moves smoothly with my player. My problem is that every time my character stops, my background kind of.. lags? Here's a video.
My view follows a "obj_dummy" object, that follows my player. I used this tutorial to make the parallex background and put the commands (background[0]=round(view_xview /1.2)....etc) in my player's step event. This is the tutorial I used for player movement.
The problem seems to be related to the character's movements, since the character kind of goes a few pixel back after you release you key. I tried fixing this with distance_to_object command, but as you can see from the video, it doesn't help. I also figured maybe telling obj_dummy to not move if player has moved under, for example, 2 pixels, but I can't seem to figure out how to do it.
I have tried solving this myself and googling a lot, but I can't seem to find an answer. Does anyone have any ideas how to fix this?
My code for obj_dummy following player (obj_hero_pf) in obj_dummy's step event
My player movement + parallax background in obj_hero_pf's step event
So, I want a parallex background that moves smoothly with my player. My problem is that every time my character stops, my background kind of.. lags? Here's a video.
My view follows a "obj_dummy" object, that follows my player. I used this tutorial to make the parallex background and put the commands (background[0]=round(view_xview /1.2)....etc) in my player's step event. This is the tutorial I used for player movement.
The problem seems to be related to the character's movements, since the character kind of goes a few pixel back after you release you key. I tried fixing this with distance_to_object command, but as you can see from the video, it doesn't help. I also figured maybe telling obj_dummy to not move if player has moved under, for example, 2 pixels, but I can't seem to figure out how to do it.
I have tried solving this myself and googling a lot, but I can't seem to find an answer. Does anyone have any ideas how to fix this?
My code for obj_dummy following player (obj_hero_pf) in obj_dummy's step event
Code:
if (distance_to_object(obj_hero_pf) < 10)
{c_spd = 0;}
else
{
c_spd= round((obj_hero_pf.x-x)/20);
}
if ( instance_exists(obj_hero_pf)){
obj_dummy.y = obj_hero_pf.y-30;
obj_dummy.x += c_spd;
}
My player movement + parallax background in obj_hero_pf's step event
Code:
//player’s input
key_right = keyboard_check (vk_right);
key_left = -keyboard_check (vk_left);
key_jump = keyboard_check_pressed (vk_space);
key_run = keyboard_check (vk_shift)
//React
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;
if (place_meeting(x,y+1,obj_wall))
{
vsp = key_jump * -jumpspeed
}
//Horizontal Collision
if place_meeting(x+hsp,y,obj_wall)
{
yplus = 0;
while (place_meeting(x+hsp,y-yplus,obj_wall) && yplus <= abs(1*hsp)) yplus += 1;
if place_meeting(x+hsp,y-yplus,obj_wall)
{
while (!place_meeting(x+sign(hsp),y,obj_wall)) x+=sign(hsp);
hsp = 0;
}
else
{
y -= yplus
}
}
x += round(hsp);
//Vertical collision
if (place_meeting(x,y+vsp,obj_wall))
{
while (!place_meeting(x,y+sign(vsp),obj_wall))
{
y+= sign(vsp);
}
vsp = 0;
}
y += round(vsp);
if (key_run)
{
movespeed = 5;
}
else {
movespeed = 3;
}
//Walk area
x = clamp(x, 16, room_width-16);
y = clamp(y, 60, room_height);
///background
background_x[0] = round(view_xview /1.2);
background_x[1] = round(view_xview /2.2);