I’m looking to make a 2D top down platformer. I want it to have the ability to jump on boxes / platforms or drop / jump off them.
I fiddled around and have some logic working but it’s still giving a lot of issues in certain situations. Which makes me question if I’m approaching it the right way. I could not find any usefull Unity toturials.
What is the best way to aproach this?
At the moment I have colliders for platforms or boxes that disable when the player is in a jumping state. And depending on OnTriggerEnter2D, they will stay off when the player is “on” then…
But it gives issues like on this image
The orange collider will disable when the player is jumping… the player on the right will do a proper jump and be blocked by the green collider and land on the black platform.
But the player on the right will immediatly trigger the OnTriggerEnter so It won’t look, feel like a jump.
I think by doing lots of checks I can avoid this but it feels hacky and there are still other situations like jumping towards to bottom of the screen or jumping towards the top of the screen that will give issues with this approach.
Any thoughts or suggestions?
So this is quite confusing. First, you say you are doing a top-down 2D platformer, but your image looks like a regular platformer. If it was truly top-down, we would only see the head of the player. To add to that point, if this image is what you are still wanting to do, you can just copy elements from a normal platformer tutorial (there are tons) to get it to work. Second, you say you want the ability to jump on and off platforms, but you also mention they can but it looks weird. Can you explain what you are trying to do with those triggers more? Maybe even share some code (with code tags) of those platforms?
Ok, sorry for the confusion. I’ll try to explain it better.
So it is not top down exactly from above but from an angle. This game is the exact example of it:
Maybe there is another name for it then top down?
You stated I could use elements from a normal platformer but that is not the case because for normal 2d platformers you can just easily work with gravity and have a line over the x axis as your ground but in this case ground is on the X and Y axis.
As I have it now, when jump is pressed, I have a jumptimer running. From 0 - 50% of the jumpTime I do velocity on the player rigidbody on the Y, from 50% -100% I do negative velocity on the Y.
When the player in the jumpState, colliders are turned off so it is possible to jump on the platform. But as for now, the jump will be finished when the jumpTimer has reached 100%. So in the case the player jumps from the ground on to a platform, it doesn’t look he landed on a higher place, because it lands on the same Y position as when he started the jump.
Now that I’m writing this down I think a possible solution for this is to disable the colliders when the jumpTimer is at 50% aka the highest point on the jump and stop the jumpState and don’t do a negative veloctity on the Y if the player is on a platform… I’ll try that out.
But still wondering if this is the way people do this or is there another solution I’m not seeing
you cant use 2d colliders for this, youll have to make your own collisions and treat it like a 3d space, then convert the 3d positions to actual display positions
2d.y = 3d.y+ 3d.z