0 votes

So, I want to make a simple non-platformer 2D game. There will be a floor, and the player character walks side to side on the floor. However, I still want the character to be able to jump (it will be completely useless though), so I can't just not take inputs from the up button. Also, the height of the floor will vary from scene to scene, so I can't just set it as a variable in the player script. I put the floor height as a variable in the parent node's script, but that means that I can't test the player scene itself. What's the best way to go about doing this? Also, I'd like to be able to get the floor height by just dragging the player instance around the parent scene instead of just setting it as a variable.

in Engine by (7,190 points)

1 Answer

+1 vote
Best answer

Even if you don't plan to implement a platformer, I'd recommend you take a look at Godot's platformer demo. It should introduce you to everything you need.

Judging from your description, there really is no reason to keep the floor height as a variable. Just give it a CollisionShape2D with the right dimensions. Make your player a KinematicBody2D and use move_and_slide to move it (that includes the jumping) and check for collisions with the floor.

by (10,315 points)
selected by

Thanks, that project really helped!

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.