0 votes

Hi I'm starting with godot, I try to make my player (a simple square) turn in the style of geometry dash, this would be when it jumps turn up to 90 degrees when it reaches the ground.

The only thing I managed to do was to use rotation_degree, but this gives me sharp turns and what I would like is to do it progressively.

var motion = Vector2()
const JUMP = 400

if Input.is_action_pressed("ui_up"):
    if is_on_floor():
        motion.y = -JUMP
        rotation_degrees +=  90
in Engine by (12 points)

1 Answer

0 votes

If you want to a continuous rotation (= a changed rotation value in every frame), you need to do the change in the process (or physics_process) function.

Let's assume you have a variable is_jumping which is true while your player is in the air and false when he's back on the ground. Then you can simply add this code to your process function:

if is_jumping:
    rotation += 5 * delta
    rotation = stepify (rotation, PI / 2.0)

Means: Rotate while jumping, and snap to the closest 90° angle otherwise.

by (1,742 points)

Thanks, this solve my problem!

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.