I’m implementing a 2.5D game, and I’d need to have raised ledges that the player should be able to jump onto.
In all 2.5D implementations I’ve seen (which don’t allow jumping), the developer sets gravity to zero and just modifies the player’s Y coordinate to have them walk away from and towards the camera.
The problem is, if I have to disable gravity, I can’t figure out how to implement jumping.
Does anyone have any suggestions on how to implement z-axis movement without disabling gravity?
You could use 3d physics and view the game like it was a tilted angle 2d game… instead of doing jumping manually.
If you really want to do this manually, you could just do it so that you have a jump state. When player jumps, you have a variable for velocity, which you set to max velocity when character starts jump. Then each step of jump reduce the “velocity” y value and move the player with velocity, i.e. sprite will move first “up” along y-axis. Reducing the velocity will eventually make your character “fall” i.e. move down along y-axis. Stop the movement and exit jump state when you are on y-position that matches the starting height of the jump.
If you want to implement jumping manually you’ll have to take care of everything yourself; the movement like explained above, possible disabling of collisions, fake shadow for jumper, sorting and so on. Allowing movement along floor plane during jump (air control) is another thing.
Figuring out landing on the platform could be done by shape or raycasting when jump state is enabled and velocity is negative. If player touches platform floor, make player grounded. Although I have no idea how exactly this would work, as platform might be a wide area instead of nearly 2d platform… which you haven’t specified. And is your other platform behind the current plane where player is walking, or directly above the player?
I have never implemented this but it is a common old school technique and it is not specific to Unity, so google to find out how others have done this earlier.
2.5D it’s best to lock movement on the X-axis. You’re basically making a 2D game in 3-D space. So why not use the standard 2D axis? Then all you need to do is turn on gravity for your player. Z-axis movement, maybe you should save when you know more about programming? Stick to the basics. Just my thoughts.
Yeah, I know full well how to implement accelerated motion in programming.
I’m just new to Unity, and had only gotten into 2D, but I guess I’ll be better off switching to true 3D.
That’s not like that if you jump from the ground and land on a platform.
It’s not easy at all.
I didn’t really get that.
I don’t have floor-over-floor. The platforms are just raised floor which you can’t walk under.
Lock movement on the X axis? Didn’t get that either.
My game allows movement on X (left-right), Z (away and towards camera) and Y (jumping). Not sure how locking the X axis would work.
2.5d perspective games like Golden Axe IIRC had this feature you could jump on a level that was behind the flat floor, or there were height differences that are full z-depth axis wide so you can jump “up” while being closer to bottom of screen or other way round to jump on that level.
The way you posted it looks as though you’re trying to move on the Z-axis which means your X and Y axis could be altered. So instead of gravity pulling you downwards it may pull you towards/away from the camera. I don’t know what axis you have what on, yanno?
So if camer is on Z-axis, the player moves left/right on the X-axis, and would jump/fall on the Y-axis, then to jump all you need to do is go to your player’s Rigidbody2D component and set gravity to 1.
As far as locking the X-axis, you’d actually be locking the player object to movement on the X-axis, not locking the axis itself. Sorry for that confusion.