Godot Version
v3.2.3.stable.official
Question
Okay, so I’ve had this problem for a while.

As you can see, the animations are no bueno. That’s not how people walk. I’ve been trying to fix this for like, months.
Now, I know why this is happening. It’s because the code I wrote for it is unfinished. Like, I started trying to fix it, but I got distracted, and now it’s almost definitely broken at this point. I mean it doesn’t really matter because the code probably wasn’t really good to begin with.
Here’s the code that handles that character’s movement:
extends KinematicBody2D
onready var animation_tree = $AnimationTree
onready var wait_timer = $wait
onready var toshi = .get_parent().get_node("toshi")
onready var state_machine := animation_tree.get("parameters/playback") as AnimationNodeStateMachinePlayback
var current_state = STATE.IDLE setget set_current_state
var playback
func set_current_state(new_state):
if(new_state == current_state):
return
match(new_state):
STATE.IDLE:
state_machine.travel("idle")
STATE.WALK:
state_machine.travel("walk")
current_state = new_state
var SCHMOOVE_ACTIVATE = true
var SCHMOOVE_CHECK
var velocity = Vector2.ZERO
var speed = 200
enum STATE { IDLE, WALK }
var time = 0
var duration = 20
var follow_speed = 20
var follow_distance = 30
func _ready():
playback = $AnimationTree["parameters/playback"]
func _process(delta):
yield(get_tree().create_timer(1.0), "timeout")
update_animation()
velocity = Vector2(1, 0).normalized() * speed
if Global.toshiPos.size() > 0:
var target_position = Global.toshiPos[Global.toshiPos.size() - 1]
var direction = (target_position - global_position).normalized()
var distance = global_position.distance_to(target_position)
if distance > follow_distance:
global_position += direction * follow_speed * (distance - follow_distance) * delta
func update_animation():
if Global.toshiAnim.size() > 0:
var target_animation = Global.toshiAnim[Global.toshiAnim.size() - 1]
if target_animation == "walk":
self.current_state = STATE.WALK
elif target_animation == "idle":
self.current_state = STATE.IDLE
…And here’s some context!
- Global.toshiAnim is an array that saves the current animation of the frontmost player.
- The variable “toshi” refers to that character’s node.
- I think SCHMOOVE_ACTIVATE and SCHMOOVE_CHECK refer to whether or not the character is moving. (In case you couldn’t tell, I have a very weird file naming convention.)
I would appreciate if someone could find where the problem(s) are. Thank you!