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

Legacy GM I need some help with player controlled object in a path

L

Lobos

Guest
Hi guys!

I need some help with my game, hope someone can help me out. I try to make a player-guided platform, which can move along a pre-determined path indefinetly. I think maybe it works with paths, but I can’t figure it out, how.

My goals are:
  • the player have two inputs (like GO LEFT/GO RIGHT) - thats OK, code done, a simple "if(keyboard_check("
  • the object can only move along the path - thats OK too (if I use a path and use "absolute: true")
  • the object could move toward the two endpoint at any time, when the player press one of the buttons, even when the path is curved, a loop or other shape (and stops, when no button pressed) - without a path, I use "if pressed; x +=" - maybe I could swap x with a path endpoint?
  • the object stops when reaches one endpoint, but don’t go backwards, unless the player press the other button
  • the object cannot leave the path - thats OK with path
  • also, the player start in the middle of the path, but I can avoid this by simply make a separate spawn point


I started with a simple path
Code:
path_start(path0, 5, path_action_continue, true);
Aaand stuck - maybe If I change the speed (5 in this example) to a variable and make a step event to swap speed/negative speed when pressed the left/right button, but thats hardly the most elegant and easy way, if it works at all.

Can I make a simple If I press the button, move towards the left path endpoint? (there are more than one path, so the fixed coordinates don't work for me)

Hope you got some usefull code/suggestion.

Thanks for the help/time for read all of this.
 

Attachments

PlayerOne

Member
It's been a while since I used paths, but maybe you can try something like this:

Code:
STEP EVENT, PLATFORM OBJECT
if place_meeting(x,y+1,obj_player)
{
     if keyboard_check_pressed(vk_right)
     {
     path_speed = player_speed_right
     }
     else if keyboard_check_pressed(vk_left)
     {
     path_speed = player_speed_left
     }
     else
     {
     path_speed=0
     }


}
When the player collides with the platform and moves either left or right the path will move in the same direction. If no key is pressed then the path based object will not move. This is all assuming that the object in question is stationary (no speed) when the player collides with the platform. Mind you this is an example and something you can't just copy and paste. With some tweaking you could get this to work.
 
L

Lobos

Guest
That was fast, thanks.

It's works...kinda.

(quick note: It's a Breakout/Arkanoid style game, the object /the paddle/ is the player, not a platformer where the player jump onto, but I just copy your code and strip the first if)

Also, I changed the "keyboard_check_pressed" to "key_check", because with the first one, the paddle object move some pixel, and than the player must release and press the button again, but with key_check, it works fluidly. So my borrowed code is just this (in the step event):

Code:
if keyboard_check(vk_right)
{
     path_speed = 3
}
else if keyboard_check(vk_left)
{
     path_speed = -3
}
else
{
    path_speed=0
}

But there is still a problem: what to do in the end of the path? If I use this (in the object create event):

Code:
path_start(path0, 1, path_action_stop, true);
It stops in the path's end and stuck. If I use path_action_continue, the object never stops and just exit the screen:
Code:
path_start(path0, 1, path_action_continue, true);
(path_action_restart and path_action_reverse also not an option)

Is there a way to avoid this?
 

PlayerOne

Member
Ah. I thought it was a platform game. :p

You shouldn't declare path functions in the create event. Use it in the step event in the object before the movement code.
 
L

Lobos

Guest
Ok, but how? (I never used paths before and I don't have a clue).
Regardless, I moved the same code from the create into the step event, as you suggested:
Code:
path_start(path0, 1, path_action_stop, true);

if keyboard_check(vk_right)
{
     path_speed = 3
}
else if keyboard_check(vk_left)
{
     path_speed = -3
}
else
{
    path_speed=0
}
But now the paddle just stuck, move once if the key pressed, and than jump back the starting point. It happens if I change the path's endaction and absolute too.

Also, if I create a path_positon and put into the step event, the object jump to a random place on the path, but immediatly jump back where it was, so I screwed up something (the object is visible, not solid and only this code exist within the object, + a separate R is restart), so I don't even know, where is the problem.

Code:
if keyboard_check_pressed(vk_up)
{
     path_position = random(1);
}
 
Top