Character Controls like Toki Tori 2

Hmm, ok, so if you want to add ladders or something the player can climb then you need to do a couple of different things:

  1. Create game objects with ladder graphics and a collision object with a new collision group “ladder”
  2. You need to add the “ladder” group to the player’s collision object so that it will detect collisions with the ladder
  3. In the player script’s on_message() function you need to check if the player has collided with the “ladder” group when you get a colision response message. When this happens you set a flag on the player script saying that the player is on a ladder.
  4. When the player presses up/down in the on_input() function of the player script you need to check if the “collide with ladder”-flag is set and if that’s the case you move the player up/down
  5. You need to modify the player script so that you don’t apply gravity if the “collide with ladder” flag is set

If you want to make a stomp-like move (I assume jump and press a key to stomp):

  1. Either define a new key to trigger the stomp action or decide if the jump button should also trigger a stomp
  2. Check in on_input() if the player triggered a stomp action and check if the player is jumping (and perhaps moving up but maybe not down)
  3. If the conditions for a stomp has been met then modify gravity so that the player falls down a bit faster and set a stomp flag on the player script.
  4. When you get a collision response in on_message() that indicates if the player has landed then also check if the stomp flag is set. If the stomp flag was set then trigger whatever effect you had in mind (perhaps destroying the ground or damaging enemies)

Read more about the physics system in Defold here: http://www.defold.com/manuals/physics/ And about how to handle input here: http://www.defold.com/manuals/input/

2 Likes