Hello Guest

Author Topic: How to make a player jump through a platform from below and stand on the platfor  (Read 6435 times)

liyao0602yy

  • Newbie
  • *
  • Posts: 3
    • View Profile
How to make a player jump through a platform from below and stand on the platform after the player falls from above of it?Also,the player should walk through the platform when the platform is in font of it.
I used the tk2dtilemap to create the platform. Is it any easy approaching to handle this?Thanks.

oug

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
    • View Profile
A simple solution would be to create a script that disables the collider of the platform when the player is below the collider and re-enables the collider when the player is above the collider.

It might not be the most pretty solution, but it works like a charm (I've used this a lot in platformers).

liyao0602yy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Thanks for your reply,oug!
But if I have many platforms like this in a tiled map,do you mean to disable all colliders above the main character in update()?However what if an enemy is on a platform through which the character should be walking?In this case,we should disable the platform collider for the character as well as enable it for the enemy, which gets conflict.

These things have put me crazy.I even think I'd rather write my game with opengl or directx rather than in unity........

oug

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
    • View Profile
Thanks for your reply,oug!
But if I have many platforms like this in a tiled map,do you mean to disable all colliders above the main character in update()?However what if an enemy is on a platform through which the character should be walking?In this case,we should disable the platform collider for the character as well as enable it for the enemy, which gets conflict.

These things have put me crazy.I even think I'd rather write my game with opengl or directx rather than in unity........
Yeah this trick is a bit annoying with a lot of platforms and enemies. What I did was the following:

- Create 2 colliders per platform, one for the enemies and one for the player
- The platform checks (put like a player-check-script on the platform itself) if the player is either above or below the platform
- The script checks (indeed in an update or lateupdate (http://docs.unity3d.com/Manual/ExecutionOrder.html) the position of the player('s feet)
- The platform disables its playercollider when the player is below the platform and
- The platform enabled its playercollider when the player is above the platform
- The enemy-collider is always enabled and doesn't do any checks on the player


This is a simple solution if you have few platforms. If you have A LOT of platforms on screen or in your scene you can do:
a. Either remove all non-visible platforms or disable the player-check-script on platforms not visible by the player
b. Do an area-check from the player that disables any colliders above the player, and enables any colliders below the player (maybe try a simple version with a triggerbox above the player and a triggerbox below the player for instance) within a certain vicinity.

I had a lot of use from the tutorials by Sebastian Lague. He wrote an amazing series on platform controllers using 2d Unity5: https://www.youtube.com/playlist?list=PLFt_AvWsXl0f0hqURlhyIoAabKPgRsqjz Definitely check it out.

And yeah, I agree: Unity isn't the optimal solution for 2d games. But with the use of tk2d, I've been able to create multiple 2d apps and games in a jiffy :) Keep at it, it'll be worth it in the end :)

(I've made these as a small one day / one week project to test out the approach by Sebastian Lague and I think it's valid: https://www.youtube.com/watch?v=3eYa0aYzQWc & https://www.youtube.com/watch?v=TA5WNqIOGEE)
« Last Edit: February 24, 2016, 09:52:45 am by oug »

liyao0602yy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hi,aug,it's so kind of you.
I'll have a try on your suggestion!Thanks so much.

oug

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
    • View Profile
Hi,aug,it's so kind of you.
I'll have a try on your suggestion!Thanks so much.
My pleasure :)

Good luck!

yo_milo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile