• 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 How to make a line that follows the player?

J

Juise

Guest
Hey there! My first post here so please forgive me if I didn't explain this problem well enough. I tried to add screenshots of the game in this post but I got an error while doing so. If anyone knows why then let me know that too. Thanks already in advance :)

I try to make TRON inspired game where 2 players create lines that kill them if they are touched. I've created an object called "obj_line1" which has a square sprite. The idea here is that the player would create these squares all the time with this command:

instance_create_depth(x,y,1,obj_line1);

It works perfectly until the player's speed increases (and I want that to happen) which makes the line have small gaps between each square since the game doesn't create them fast enough.

I've tried to repeat that command multiple times but then squares are just created on top of each other which doesn't resolve this issue. I also played with draw line events but couldn't come up with anything useful.
 

Nidoking

Member
When the player's speed increases, instead of moving it multiple squares in a single step, you should move it one square, check for collision with a obj_line1, create a new obj_line1, and then repeat that (player_speed) times.
 
J

Juise

Guest
When the player's speed increases, instead of moving it multiple squares in a single step, you should move it one square, check for collision with a obj_line1, create a new obj_line1, and then repeat that (player_speed) times.
Sorry but I don't know how to make it move just one square because I want to make the player go faster as the time goes on. And the collision thing just crashed the game so it won't work either.
 

TheouAegis

Member
First off, creating a bunch of objects like that will kill memory and slow the game down. You could cut down on objects by only creating a new object when turning. Save the id of the newly created object in the bike. Every step, set that object's xscale or yscale by how far the bike is.
 
D

dannyjenn

Guest
Yeah, the way you're doing it isn't very good with regard to performance.

But if you are going to do it that way, all you need to do is make sure there aren't any gaps. A simple loop should solve the problem.
Code:
// bike's end step:

// if moving rightwards horizontally:
for(i=xprevious; i<x; i+=sprite_get_width(spr_square)){
    instance_create_layer(i,y,"Instances",obj_square);
}

// leftwards movement is done the same way, as is vertical movement

edit - Personally, I'd just use lines and collision_line. You could put down a node object every time the bike turns, and then simply loop through the nodes and draw lines between them to draw the walls, and check collision_line on each line to check for collisions.
 

TheouAegis

Member
Yeah, the way you're doing it isn't very good with regard to performance.

But if you are going to do it that way, all you need to do is make sure there aren't any gaps. A simple loop should solve the problem.
Code:
// bike's end step:

// if moving rightwards horizontally:
for(i=xprevious; i<x; i+=sprite_get_width(spr_square)){
    instance_create_layer(i,y,"Instances",obj_square);
}

// leftwards movement is done the same way, as is vertical movement

edit - Personally, I'd just use lines and collision_line. You could put down a node object every time the bike turns, and then simply loop through the nodes and draw lines between them to draw the walls, and check collision_line on each line to check for collisions.
You wouldn't need objects for that, even! Just store the coordinates of each node in an array.

I was somewhat curious how they did it in the old Macintosh game I used to play at school that allowed 4 players. There was no color differentiation, so I would suspect they just store all player's trails and one giant array. The game played fast and smoothly on such an old system, so I suspect that code was simple and light on data usage...
 
Top