- Edited
Hello!
So, I'm going for Silent Hill 1 tank controls, and have my movement script sorted (I settled on using a version of this tutorial's code as it's really straightforward). Full code below! nb. I'm new to Godot but not game design, although I'm very much a hobbyist. I'm using Godot 4.1.
An Animation Tree looked like this would be the best way to handle everything, and this is 99% set up so the correct animation triggers at the right time (at the moment: idle, walk, run, walk back, run back, turn left/right).
HOWEVER. Running (forwards and backwards), turning (left and right), and walking backwards animations aren't playing correctly eg. they don't run through their full loop, or they 'snap' the player to a position they should not be in.
I exported animations from Mixamo 'in place' and set them up in Blender without loops so I could better test looping in Godot, but this doesn't seem to make any difference to the issues (ie. looping on and off both result in the same glitches).
Xfade time for every animation is 0.2.
Switch mode for every animation is 'sync'.
I don't know if this helps, but I've attached a screenshot of the Animation Tree, and the player script is below. If it would help anyone help me figure this out, here's a link to the project..
extends CharacterBody3D
@export var SPEED = 0.5
@export var TURN_SPEED = 90
@onready var animation_player = $AnimationPlayer
func _physics_process(delta):
var move_dir = 0
var turn_dir = 0
if Input.is_action_pressed("turn_right"):
#rotate_object_local(Vector3(0, 1, 0), 0.1)
turn_dir -= 1
if Input.is_action_pressed("turn_left"):
#rotate_object_local(Vector3(0, 1, 0), -0.1)
turn_dir += 1
if Input.is_action_pressed("move_back"):
move_dir -= 1
if Input.is_action_pressed("move_forward"):
move_dir += 1
if Input.is_action_pressed("run") and Input.is_action_pressed("move_forward"):
move_dir += 2
if Input.is_action_pressed("run") and Input.is_action_pressed("move_back"):
move_dir -= 2
rotation_degrees.y += turn_dir * TURN_SPEED * delta
velocity = global_transform.basis.z * SPEED * move_dir
#Animation Tree states
#IDLE
$AnimationTree.set("parameters/conditions/Idle", !Input.is_anything_pressed())
#WALK
$AnimationTree.set("parameters/conditions/Walk", Input.is_action_pressed("move_forward"))
#WALK BACK
$AnimationTree.set("parameters/conditions/Walk Back", Input.is_action_pressed("move_back"))
#TURN LEFT - BIT ROUGH
$AnimationTree.set("parameters/conditions/Look Left", Input.is_action_pressed("turn_left"))
#TURN RIGHT - BIT ROUGH
$AnimationTree.set("parameters/conditions/Look Right", Input.is_action_pressed("turn_right"))
#RUN FORWARD
$AnimationTree.set("parameters/conditions/Run Forwards", Input.is_action_pressed("run") and Input.is_action_pressed("move_forward"))
#RUN BACK
$AnimationTree.set("parameters/conditions/Running Back", Input.is_action_pressed("run") and Input.is_action_pressed("move_back"))
move_and_slide()
<div style="width:100%;height:0px;position:relative;padding-bottom:66.667%;"><iframe src="" frameborder="0" width="100%" height="100%" allowfullscreen style="width:100%;height:100%;position:absolute;left:0px;top:0px;overflow:hidden;"></iframe></div>