2D Toolkit Forum

2D Toolkit => Support => Topic started by: liyao0602yy on February 19, 2016, 12:27:54 pm

Title: How to make a player jump through a platform from below and stand on the platfor
Post by: liyao0602yy on February 19, 2016, 12:27:54 pm
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.
Title: Re: How to make a player jump through a platform from below and stand on the platfor
Post by: oug on February 22, 2016, 08:52:09 am
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).
Title: Re: How to make a player jump through a platform from below and stand on the platfor
Post by: liyao0602yy on February 23, 2016, 06:59:16 am
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........
Title: Re: How to make a player jump through a platform from below and stand on the platfor
Post by: oug on February 24, 2016, 08:55:36 am
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)
Title: Re: How to make a player jump through a platform from below and stand on the platfor
Post by: liyao0602yy on February 25, 2016, 02:19:27 am
Hi,aug,it's so kind of you.
I'll have a try on your suggestion!Thanks so much.
Title: Re: How to make a player jump through a platform from below and stand on the platfor
Post by: oug on February 25, 2016, 02:18:19 pm
Hi,aug,it's so kind of you.
I'll have a try on your suggestion!Thanks so much.
My pleasure :)

Good luck!
Title: Re: How to make a player jump through a platform from below and stand on the platfor
Post by: yo_milo on March 01, 2016, 02:18:04 pm
https://www.youtube.com/watch?v=OBtaLCmJexk

Look at this.