Rotation won't work

Godot Version

4.2.2.stable.mono

Question

(Solved, thank you! :smile:)
Hello! I’m trying to make a Geometry Dash style game to just get some practice, but I’m having trouble with the flipping. It’s supposed to “land” on the side that is facing the ground, but it will just land upright. Any idea what the problem could be? Thanks! I will give more context if needed

Sprite2D (To give the effect of rotating):

extends Sprite2D

var rotEnd = 0

@onready var cube = $".." #cube is the parent node. 

func _ready():
	rotation = 0

func _process(delta):
	if !cube.isOnFloor:
		rotation += 8 * delta
	else:
		rotEnd = round(global_rotation/90) * 90
		print(global_rotation)
		print(rotEnd)
		rotation = lerp_angle(global_rotation, rotEnd, 8 * delta)

CharacterBody2D (Parent, for actually jumping)

extends CharacterBody2D

@export var JUMP_VELOCITY = 1250
@export var gravity = 3500
var lerpRotation : float = 0.0
var isOnFloor : bool = false

# Get the gravity from the project settings to be synced with RigidBody nodes.
var settingGravity = ProjectSettings.get_setting("physics/2d/default_gravity")
 
func _physics_process(delta):
	lerpRotation = rotation + 90.0
	settingGravity = gravity
	# Add the gravity.
	if not is_on_floor():
		velocity.y += settingGravity * delta
		isOnFloor = false
	else:
		isOnFloor = true

	if Input.is_action_pressed("ui_accept") and is_on_floor():
		velocity.y = -JUMP_VELOCITY
	

	move_and_slide()

Is this value used anywhere? I cannot find it in the code. Anyway, lerp_angle works with radians, not degrees, so you probably want to use deg_to_rad(90) as the increment,

1 Like

Thanks! I cleaned up my code and then realized that it’s radians, like you said. It turns out I was just dividing by the wrong amount. I have a new bug that makes it land at a weird angle, but I’ll probably figure it out on my own. Thanks so much, have a good day!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.