rotate geometry dash style

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By H_A

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
	else:
		rotation_degrees +=  90
:bust_in_silhouette: Reply From: Thomas Karcher

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
else:
	rotation = stepify (rotation, PI / 2.0)

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

Thanks, this solve my problem!

H_A | 2020-12-18 17:44