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.

asked Feb 12 in Engine by exuin (41 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.

answered Feb 12 by njamster (8,128 points)
selected Feb 13 by exuin

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.