UI Element rotation is randomly being choppy when in use

Godot Version

Godot 4.2.2

Question

Hey there I’m having an issue for some reason where the UI/card node is glitching as im moving it around, anyone know why it would be doing it since the code makes sense

Here’s the logic behind the card movement:

extends CardState
class_name Held

@export var card : Control
@export var card_UI : Control
var drag_offset = Vector2.ZERO

@export var rotation_amount: float = 45.0  # Maximum degrees of rotation
var previous_position = Vector2.ZERO
var velocity = Vector2.ZERO

var previous_mouse_position = Vector2.ZERO
var smoothed_velocity_x = 0.0

func enter():
	set_drag_offset()
	velocity = Vector2.ZERO
	previous_position = card.position
	previous_mouse_position = get_viewport().get_mouse_position()
	card.pivot_offset = card_UI.size / 2
	

func set_drag_offset():
	drag_offset = get_viewport().get_mouse_position() - card.position
	pass

func exit():
	pass

func update(delta: float):
	var current_mouse_position = get_viewport().get_mouse_position()
	var mouse_delta = current_mouse_position - previous_mouse_position
	previous_mouse_position = current_mouse_position
	
	card.position = lerp(card.position, current_mouse_position - drag_offset, 0.8)
	var mouse_velocity_x = mouse_delta.x / delta
	smoothed_velocity_x = lerp(smoothed_velocity_x, mouse_velocity_x, 0.2)
	apply_rotation_based_on_velocity(smoothed_velocity_x)


@export_group("Rotation Weight")
@export var max_velocity = 2000.0
@export var rotation_ease_in_weight: Curve
func apply_rotation_based_on_velocity(velocity_x):
	var horizontal_velocity = abs(velocity_x)
	var t = clamp(horizontal_velocity / max_velocity, 0.0, 1.0)
	var eased_t = rotation_ease_in_weight.sample(t)
	var rotation = eased_t * rotation_amount * sign(velocity_x)
	
	card.set_rotation_degrees(lerp(card.get_rotation_degrees(), rotation, 0.45))

It’s probably gonna be a really stupid fix on my end but I cannot seem to figure it out :confused:

What’s wrong with it? Rotation looks nice, is it not supposed to darken when still?

What do you expect to happen vs what is really happening?

1 Like

Thanks for responding :smiley:
Later on in the video the cards rotation starts to glitch out as its moving around which isn’t what I want to happen.
The red is just the debug draw call which isn’t an issue

what I am looking for? What is a “glitch out”

1 Like

Oh my bad, when I say “glitch out” I mean card become choppy as it moves.

You can see it happen around 0:07 and 0:13 into the video

That seems to be the exact timestamps for the steam popup beginning and ending

1 Like

I’ve got another video of it being choppy without the steam notification. I’m just gonna try reset my computer and see what happens