GameMaker: Studio

GameMaker: Studio

View Stats:
Kihunter Feb 9, 2015 @ 6:12pm
Object Follow Lag
I have an object(obj_2) on top of another object(obj_1). Using global varibles, obj_2 should follow obj_1 perfectly yet it trails behind whenever obj_1 moves. It'll sync back up, but the lag is very unsightly. I've tried fiddling around with vspeed and hspeed as well, but they desync rather quickly.

Code:


obj_1 Step Event:

global.x_val = x
global.y_val = y

obj_2 Step Event:

x = global.x_val
y = global.y_val
< >
Showing 1-8 of 8 comments
Blind Feb 9, 2015 @ 6:15pm 
Increase room speed, or increment globals in the begin step so that it's sync'd properly in the main step.
Thew Feb 9, 2015 @ 6:52pm 
This is a common problem. There are a few ways to solve it, but it depends on the specifics of your situation.

If you're just trying to have two images overlap (like say, a weapon/armor overlapping a player sprite) you can manually draw the second object in the first object's draw event.

This topic addresses this issue a bit: http://gmc.yoyogames.com/index.php?showtopic=562508
Sera Feb 9, 2015 @ 9:46pm 
Your trailing objects are updating their position before the player moves, most likely. this is commonly a depth thing, but fixing that could be a slight pain if you want things to draw in a set order.

An alternative could be to have a with statement move the trailing objects at the same time you move the player fomr the player object. This all happens before the Draw event, so it should theoretically force things into sync.
Blind Feb 9, 2015 @ 10:17pm 
Another thing is you can do pre-movement calculations in the step, but not actually move them until the end step - that will also keep things synced
Kihunter Feb 10, 2015 @ 1:10pm 
Fixed it: boosted the room speed to 60 and worked some coding to make the object follow seemlessly. Thanks for the advice!
NokturnalRealms Feb 13, 2015 @ 5:53pm 
also just a note you can use the End Step event and move the following object at the End Step instead of Step.
Blind Feb 13, 2015 @ 5:57pm 
Yes, the actual problem is the order of operations - Object1 isn't getting information from Object2 until the next step, it's the reason there's a Begin/Normal/End step, so data like this is synchronized before going to the Draw phase
the tickler Feb 14, 2015 @ 2:59am 
set room speed higher....
< >
Showing 1-8 of 8 comments
Per page: 1530 50

Date Posted: Feb 9, 2015 @ 6:12pm
Posts: 8