#logicalposition
The character shakes when moving
Jumpshare ### UnknowWay (DEBUG) 2025-02-27 20-30-06.mp4 Shared with Jumpshare Duration: 12 Okay. The video shows the problem, and the photo with the tree. Code: using Godot; using System.Diagnostics; public partial class Player : CharacterBody2D { [Export] public int Speed { get; set; } = 100; private Vector2 inputDirection; private Vector2 inputDirectionFiltered; private Vector2 logicalPosition; public AnimatedSprite2D character_2d; public Label debugText; public override void _Ready() { inputDirectionFiltered = Vector2.Zero; logicalPosition = GlobalPosition; debugText = GetNode<Label>("Debug"); character_2d = GetNode<AnimatedSprite2D>("AnimatedSprite2D"); } public override void _Process(double delta) { if (inputDirection != Vector2.Zero) { if (Input.IsActionPressed("up")) { if (Input.IsActionPressed("right")) { character_2d.Play("forward_right"); } else if (Input.IsActionPressed("left")) { character_2d.Play("forward_left"); } else { character_2d.Play("forward"); } } else if (Input.IsActionPressed("down")) { if (Input.IsActionPressed("right")) { character_2d.Play("backward_right"); } else if (Input.IsActionPressed("left")) { character_2d.Play("backward_left"); } else { character_2d.Play("backward"); } } else if (Input.IsActionPressed("left")) { character_2d.Play("left"); } else if (Input.IsActionPressed("right")) { character_2d.Play("right"); } } string vectorStr = inputDirection.ToString(); debugText.Text = vectorStr; } public override void _PhysicsProcess(double delta) { inputDirection.X = Input.GetActionStrength("right") - Input.GetActionStrength("left"); inputDirection.Y = (Input.GetActionStrength("down") - Input.GetActionStrength("up")) / 2; if (inputDirection.LengthSquared() > 0) inputDirection = inputDirection.Normalized(); Velocity = inputDirection * Speed; MoveAndSlide(); } }
forum.godotengine.org
February 28, 2025 at 8:41 AM