Vertical and horizontal moving platform problems!

Hi, I am in the finishing stages of my first game, yeeah! I really love LUA and Corona but sometimes it’s easy to get stuck and now i am there again :slight_smile:

I am having platforms in my game that moves in two directions. Both horizontal and vertical. I managed to get the player on to those platforms when it moves and so far it is ok. I am also using physics for my game and I think that it did not get easier with that - but on the other side the gamefeeling is awesome!

Problem

When the player is traveling on a platform that moves vertical, he doesn’t jump of the platform? It works perfect on the platforms that moves horizontal? I am using levelHelper for creation of levels, you will see some code I am using to interact with objects in my code.

In my collision routine I have this code to see if the player is hitting a moving platform:

elseif event.other.lhTag == LevelHelper\_TAG.MOVING then  
  
 --=======================================================  
 -- MOVING PLATFORMS  
 --=======================================================  
  
 if (attachedPlatform==false) then  
 --Create an instance to the moving platform  
 ActivePlatform = loader:spriteWithUniqueName(event.other.lhUniqueName)  
  
 --Check that collision occurs on top of platform  
 if (ActivePlatform.y - ball.y\>12) then  
  
 --Offset of player and platform  
 PlatformOffset = ActivePlatform.x - ball.x  
  
 --Check that the player hits inside the platform and not on edges.  
 if(PlatformOffset\>-40 and PlatformOffset\<40) then  
  
 --Change tag on sprite to avoid any more collisions right now....  
 ActivePlatform.lhTag = LevelHelper\_TAG.DEFAULT  
  
 --Player can jump  
 ball.jumping = true  
 --player is attached to the platform  
 attachedPlatform = true  
 end  
 end  
 end  
  
else  
 ball.jumping = true  
end  

So then we have the player attached to the platform, and in my onEnterFrame I have this code:

if attachedPlatform then  
 --Ball is following the horizontal movement of the platform  
 --No control of Y since the fact that physics takes care of this for vertical moving platforms.  
 ball.x = ActivePlatform.x - PlatformOffset  
 ball.jumping = true  
end  

and then I have this code in the jump function for my players character…

 if(attachedPlatform) then  
 --We are just about to jump, so we are not attached any more....  
 attachedPlatform = false  
  
 --xGravity is a global value collected from joystick or gyroscope  
 ball:applyLinearImpulse((xGravity\*-1)/2, -12, ball.x, ball.y)  
  
 --Put back the tag on the platform to avoid doubbletap to get loose....  
 local listener = function()  
 ActivePlatform.lhTag = LevelHelper\_TAG.MOVING  
 end  
  
 timer.performWithDelay(100, listener )  
  
 else....  

Any ideas of why I can’t jump of platforms that moves vertical?

Best regards, Joakim [import]uid: 81188 topic_id: 21373 reply_id: 321373[/import]

I can’t recall off hand what the solution was but if you do a search we had a thread or two about making games like Doodle Jump and how to handle moving platforms, jumping, etc. that I believe may be of some use to you.

Peach :slight_smile: [import]uid: 52491 topic_id: 21373 reply_id: 84744[/import]