0 votes

Hey guys. I'm learning godot and so far it's been a delight!

I am wondering how I can go about getting my player character to move.
My "character" scene is set up as follows:

= Armature
== Skeleton
=== Mesh
= Animation Player
= Animation Tree
= Root Motion View
= Kinematic Body
== Collision Shape

The animation tree is correctly set up, I know this because the Root Motion View moves according to the position of my character's hips. This is a combination of mixamo animations exported with blender BTW.

So I save this scene and add it to my level, and then attach this script:

extends Node

func _input(event):
    if event.is_action_pressed("ui_up"):
        $AnimationTree["parameters/speed/blend_amount"] = 0
        var xform = $AnimationTree.get_root_motion_transform()
        $KinematicBody.move_and_slide(Vector3(  0, 0, 1))

    if event.is_action_released("ui_up"):
        $AnimationTree["parameters/speed/blend_amount"] = -1

So the animation plays properly, but the character doesn't move at all.

Any thoughts? Thanks!

in Engine by (12 points)

1 Answer

+1 vote

$AnimationTree.get_root_motion_transform() will gives the transformation of the root motion, apply it to your KinematicBody

var rmt = $player/AnimationTree.get_root_motion_transform()
var velocity = ((transform * rmt).origin - transform.origin) / delta
move_and_slide(velocity, Vector3.UP)

by (256 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.