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)