2D game with depth, basics?


I’m currently working on a 2D game with depth, something similar to Castle Crashers.

I’m trying to do the basics first(character moviment, collisions, etc), what I have so far is this:

My background is a Plane object (with a background image) facing positive Z.
Both the character and the chest make use of a 1x1 Quad (custom mesh) with their respective image. For collisions, i added a capsule collider to my character and a cube mesh colider to the chest object. My character also has a Kinematic rigid body attached to it.

I managed to create a script for moviment and collision that works as follows:

  • Moving to the Right of Left = increasing/decreasing transform.X value
  • Moving Up and Down = increasing/decreasing transform.Y and Z values
  • Collision = OnTriggerEnter

So far i had no problems, but now i’m having trouble on the jump part. As you can see i have no ground on my scene(maybe I should have?), that’s why my character’s rigid body is Kinematic. I have tried to increase the rigidbody velocity and decrease it over time, (until my character returned to the initial Y position) but it doesn’t really work…

My questions are:

  1. Should i add ground on my scene for colision? so i could use a non-kinematic rigidbody. If yes, how can i achieve this?
  2. If Kinematic rigidbody is the right choice, how can i script the jump?
  3. Does the Character Controller provided by Unity has a jump funcionality? Still, it’s restricted to a capsule collider :frowning:

I hope that anyone can help.


Instead of increasing/decreasing the velocity over time why don’t you make it more static.

Set the height of the jump. Maybe like “5” units, whatever suits your needs.

From there when you hit your jump button you use lerp to move your character 5 units up, once it has reached it’s 5 units, lerp it back down 5.


    character.transform.position = Vector3.Lerp(character.transform.position, desiredLocation.position, Time.deltaTime * speed);

When you start your jump declare desiredLocation as your current location plus 5.

Check if you have reached your destination

    public float ErrorAllowed = 0.005f; //the smaller the number the more accurate
    if (Mathf.Abs((character.transform.position.y - desiredLocation.position.y)) < ErrorAllowed) {
	    //method that goes down. Aka a bool to let you know if you are traveling up or down, and then to change the desiredLocation back to either your start location (more accurate) or current location minus 5

Now one thing I like and hate depending on what I’m doing is with lerp it gradually slows down. So you can compensate for this by increasing your speed. I do something along the lines of:

    public float FloatForSpeedUp = 1.7f; //play around with this number.
    if ((Mathf.Abs((theCamera.transform.position.y - tempPositionToGoTo.position.y)) < FloatForSpeedUp)) {
		speed+= (speed*0.04018f);

The biggest downside to this is your FPS determins a lot of the simulated physics on this. I noticed the speed at which my object excels in the editor (on my pc) is much more dramatic then on my android phone (I use these for android) basically because my computer gets 800+ FPS while my android gets 40-60. So fine tuning around will be required.

What if… You have an object that is your “Shadow” that is platform controlled in an 8 directional way, this is what you control, so it moves freely around the screen in the X and Y axis. Then you have a Platformer style Player object with Graity in the Y axis. This Player object essentially uses his “Shadow” like a hoverboard. When the shadow is moving, his walk animation goes off as he is pinned to the shadow’s movement. Then the player can initiate a jump and they’re just landing back down on a the shadow platform. Or is this just better to do with a script and an offset?