#2D Mario Physics

30 messages · Page 1 of 1 (latest)

solar shuttle
#

So, I got Mario's basic movements working nearly flawlessly in Godot 4. There's only one blip of jank, (where Mario jumps upward upon pressing the jump button when he walks over an edge) but I'm sure I'll isolate that in due time. Feedback is welcomed!

marsh storm
#

😱 I AM LOVING THIS! 😭

slim wind
#

holy crap, that's awesome!! :D
is this just gonna remain a test thing, or is this a sort of gateway into some sort of larger project...?

solar shuttle
keen blaze
#

Woah i'm curious as to how you pulled this off, im making a project that needs mario physics, and having them be accurate would be nice

solar shuttle
#

The gist I'll say right now is that Mario is a CharacterBody2D, and is not using any RigidBody physics. Mario uses linear interpolation for his left and right movement, and his jump uses a specific formula that I learned from this:

#

One other important thing I'll mention is that, even though Mario has a RectangleShape2D for his collision, I have conditions set to where he'll "snap" past solid corners if he jumps up to them and is far enough past them by the time he makes contact with them. He'll retain his upward velocity as well.

keen blaze
#

i used a curve for the jump and everything

#

or

#

not curve

#

you know what i mean

solar shuttle
#

Ah. Well, heh, fun fact, I didn't use any curve tool.

keen blaze
#

Yeah i know thats why i said not curve

#

i mean more as in controlling the curve of the jump

solar shuttle
#

Oh, I see.

#

The arc, you mean

keen blaze
#

Yeah

solar shuttle
#

Well, lemme share the magic formula. Bear in mind, this is written in C#.

keen blaze
#

i'll probably restructure my stuff some time later since i just got finished with a game jam and im real tired lol

solar shuttle
#

This method is called whenever the player presses the jump button during an "Idle", "GroundMove", or "Crouch" state in my script.

#

From my findings of the official games, Mario has 4 different jump strengths from the ground. Only one executes depending on Mario's X velocity at the frame of the jump input.

#

Thus, you see the constants: "maxStandingJumpStrength", "maxWalkingJumpStrength1", etc.

#

To clarify, these constants represent the highest Mario is able to jump if the player continues to hold the jump button during a "Jump" state.

#

Once one is assigned to the "currentJumpStrength" value, the formulae below are used to control Mario's jump arc.

#

There are a few other factors at play that allow for the perfect replication of Mario's jump to execute in Godot. But I think this is the big part of it. Hope it helps!

slim pendant
#

Very nice