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