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

Vertical moving platform stops moving if I am on it when it touches the ground

pixeltroid

Member
1. If I am NOT standing on the platform, the platform changes direction when it touches the ground normally.
2. But if I am standing on it when it touches the ground, it stops moving. Its only when I jump up does the platform starts moving.

Here's a visual of the same thing happening:

pl_prob.gif

Here are the codes for the vertical moving platform "obj_movingplatform_vnew":

CREATE
Code:
dir = choose(-1, 1);
STEP
Code:
if dir = 1 {
y+=1}
else
{y-=1}
Collision with obj_solid
Code:
dir *= -1
Collision with obj_blocker*
Code:
dir *= -1
(*basically obj_blocker is an invisible object that I place in the room editor that causes the platform to stop and change direction. This is useful because it helps me control the distance the platform moves in the room editor itself).

In the player object's step event I have this:

STEP
Code:
if place_meeting (obj_player.x, obj_player.y+1 , obj_movingplatform_vnew)
{
y += 1 * obj_movingplatform_vnew.dir
}

I have the exact same code for the horizontal moving platform (except it's "x" instead of "y") but that works fine without any issue.

Does any one know whats causing the issue? How do I fix it?

Any help would be greatly appreciated!
 
Last edited:

Slyddar

Member
Is it possible the obj_blocker and obj_solid are cancelling each other out? Add a breakpoint in the collision with obj_solid and place the player on the platform, then run in debugger mode and see what happens.
 

pixeltroid

Member
Is it possible the obj_blocker and obj_solid are cancelling each other out? Add a breakpoint in the collision with obj_solid and place the player on the platform, then run in debugger mode and see what happens.
I tested it against both the obj_blocker and obj_solid. Im still having the same issue!
 

Slyddar

Member
You should use the debugger. Put a watch on the dir variable in your platform and see what it does as you step through the code...or at least use some show_debug_message(dir) lines in the platform to see what it's doing when it's not moving.
 

Slyddar

Member
Also you could get rid of your collision events and try replacing your step with this.
Code:
if dir = 1 {
  if !place_meeting(x, y + 1, obj_solid) and !place_meeting(x, y + 1, obj_blocker)
    y+=1
  else
    dir = -dir;
}
else
{
  if !place_meeting(x, y - 1, obj_solid) and !place_meeting(x, y - 1, obj_blocker)
    y-=1
  else
    dir = -dir;
}
 

pixeltroid

Member
Also you could get rid of your collision events and try replacing your step with this.
Code:
if dir = 1 {
  if !place_meeting(x, y + 1, obj_solid) and !place_meeting(x, y + 1, obj_blocker)
    y+=1
  else
    dir = -dir;
}
else
{
  if !place_meeting(x, y - 1, obj_solid) and !place_meeting(x, y - 1, obj_blocker)
    y-=1
  else
    dir = -dir;
}

Hi. Thanks for the code. Unfortunately it didnt work. It's causing the player slides away from the platform :/

Anyway, I modified the code a bit to just work with a timer:

Create:
dir = choose(-1, 1);
timer = 0;

Step
timer += 1
if timer > 200 // I modify this to increase/ decrease the distance the platform travel
{
timer = 0
dir *= -1;
}
y += dir * 2


So yeah, I would need to calculate some things to get the distance right. But I will use this for now.

If you have an alternate way to make the old code work, i.e., change direction upon touching obj_solid please let me know.
 
D

Deleted member 16767

Guest
Hello @pixeltroid . Try making it a child to obj_solid? This is just a wild guess.

Or use mp pathfinding.
 

Joe Ellis

Member
If the problem is that the direction is switching twice per step, you could make a limit that only allows one direction change per step,
something like:

Code:
begin step event:

switched = false

collision event (with both objects):

if !switched
{
dir *= -1
switched = true
}
 

pixeltroid

Member
If the problem is that the direction is switching twice per step, you could make a limit that only allows one direction change per step,
something like:

Code:
begin step event:

switched = false

collision event (with both objects):

if !switched
{
dir *= -1
switched = true
}
hi. Thanks. I'll try your method and report back. :)
 

pixeltroid

Member
Hello @pixeltroid . Try making it a child to obj_solid? This is just a wild guess.

Or use mp pathfinding.
its already a child to obj_solid. I looked up mp pathfinding and it seems pretty complex. I'll take some time to figure out how to apply it. But I'll make it a point to study it for other uses in my project.
 
Top