+2 votes

Seems all the Platformer examples for Godot and projects on Github use Physics.

However using Physics for platformers seems to be discouraged in many blogs and resources on other engines and resources saying it leads to a lot of problems and tends to be buggy.

Seems the best way is to create a custom platforming engine (template) for Godot like most pro games do.

Am I correct?

Are there any platformer examples or source codes for Godot which implement their own engines (template) (like Corgi, Rex Engine and other paid assets for Unity)?

in Engine by (49 points)
recategorized by

Reading your question, I don't understand what you mean by "Physics".

If you are talking about collisions, I honestly don't know how someone could create a platformer without some implementation of a mechanism which prevent players from going through walls and grounds. If you are talking about trajectories of jumps for example, I guess indeed that using custom trajectories set by code is often better to get the right feeling for the player, than using physically accurate flight routes.

Could you give us one or several links to the "many blogs" you mentionned ? Could you explain why the platformer demos of Godot (for example) don't suit your needs ?

I mean something that doesn't use Box2d or physics based movement that add force to the physics bodies.

Also I haven't dived into Godot examples, I just noticed they all seemed to be physics based, I many be wrong, the terminology like Kinematic body, Rigid body makes me think they are physics based.

1 Answer

+4 votes
Best answer

KinematicBody2D is the node of choice for platformers.

Basically, the word "kinematic" in the name just means this is a node that's going to be moving around. There's no expectation for this node of what kind of movement code you're going to write for it (unlike RigidBody2D).

So, you can write whatever movement code you want. It can be as simple as move one pixel left if the left key is just pressed (that is, no real physics at all), or so complex as to involve acceleration, different kinds of friction, mass, momentum, and so on (that is, tons of "real" physics). It's up to you how much you want to code the real physics in.

When blogs warn about using "real" physics in platformers, they are being somewhat vague. Basically, they are just warning devs not to go overboard with their physics model. Stick to simple attributes like velocity, acceleration, and friction. Your Player probably doesn't need a mass attribute.

I myself have built projects using only a velocity variable (the movement is constant so long as a key is pressed, and when the key is released, movement is 0).

Also, don't be confused by Godot's virtual function _process_physics(). This is where you'll write your KinematicBody's movement code. The word "physics" in the name should be construed loosely. It's just where your movement code resides, however complex or simple it happens to be.

by (1,549 points)
selected by

Is the KinematicBody similar to Unity's built in character controller but a bit more physicsy?

That is what I'm able to infer from the examples and Gameplay of Kinematic Platformer.

Normally in other engines, people code their own character controller or platformer engine with their own system for gravity, collision and sell them as assets, because some engines don't have built in platformer/character controller support or the builtin one is very limited and not professional.

I've never used Unity, so I can't say if it's similar. But I think you're reading too much into the KinematicBody2D from the examples you've seen. As far as I know (and I use this node a lot), there are no "built-in" physics (unless you count the two common functions for collision resolution, move-and-slide, and move-and-collide). When you use the KinematicBody2D, you do end up "building your own character controller".

That is to say, you decide what physical attributes you want to give the KinematicBody2D, and you decide how to use those attributes to move the body.

It seems the move_and_slide() itself is kinda a custom implementation similar to CharacterController. It seems to handle all the collisions, slopes etc.

This is what a CharacterController does I think. Some may have less customization options while Godot's move_and_slide is more flexible but you have to write a little code or use a template or boilerplate

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.