• 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!

GML object to follow a track/rail

Hello,

On the face of it i think this is a pretty simple problem. New to GML so hopefully i just need to call the right function or start to understand the paths bit better.

so this is a top-down game, at times I want to player object to effectively connect to a rail/track, and have limited movement within that rail/track.

prefer to do with code rather than setting up paths as I'm not entirely sure im going to have static tracks/rails in the future. Also, I've seen a few tutorials but paths seem to be very focused on simple enemy/NPC movement rather than setting a rigid course that a player can move up/down/left/right on? happy if someone can show me otherwise and its the path of least resistance..

I've tried the below and this just sets a box that is the sprite width and height from 0,0 for the object to move in.

if rail = true
{

xrailmin = min(o_Rail.sprite_width-o_Rail.sprite_width);
yrailmin = min(o_Rail.sprite_height-o_Rail.sprite_height);

xrailmax = max(o_Rail.sprite_width);
yrailmax = max(o_Rail.sprite_height);


x = clamp(x,xrailmin,xrailmax);
y = clamp(y,yrailmin,yrailmax);
}

if this helps visualize, want the player to move up and down that rail only when rail = true.
upload_2018-6-29_22-34-42.png


Also, this is just a straight line on 1 axis.. looking for it to work when on curves and obtuse/acute angle changes.. i guess think the rail/conveyor system in Factorio

Thanks
 
OK.. after mulling on the paths thing.. looked up some stuff... think I'll have to play with the path functions.. seems you can assign paths in code and i should be able to vary the direction and speed with user inputs changing the variables.. let me know if im on the wrong track..

thanks
 
B

Brett Clements

Guest
OK.. after mulling on the paths thing.. looked up some stuff... think I'll have to play with the path functions.. seems you can assign paths in code and i should be able to vary the direction and speed with user inputs changing the variables.. let me know if im on the wrong track..

thanks
Let me know how you go! I’m about to build a top down ghost train game and having a kart follow the track is key. Brett
 

Joe Ellis

Member
You can make a path system with code for this kind of thing, but it gets a bit complicated when you have to make the points in the room editor. You can do a thing where you place "obj_point" one after the other and run some code when the room starts that creates a path with them. But that'll just link them together based on the order you created them in, which'd get messed up if you deleted a point and added extra ones in the middle. Really you need to make your own editor to create them properly, which is a huge thing.
I've never been a fan of paths, but they probably will be the simplest\easiest option.
 
Top