function move_and_slide() return a value but the value never use

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RGames

I am a beginner so I don’t know much. When I run this Code My character goes up to thin air. I tried so many things But none of them works. So can anyone tell me why this is happening?`

extends KinematicBody
export(NodePath) var AnimationTree
onready var _anim_tree = get_node("AnimationTree")
var gravity = Vector3.ZERO

func _physics_process(delta):
    var root_motion : Transform =_anim_tree.get_root_motion_transform()
    var v = root_motion.origin/delta
    if is_on_floor():
		gravity = Vector3.ZERO
	else :
	    gravity = Vector3(0.0 , -4.0  , 0.0)
	v+=gravity
    if Input.is_action_pressed("ui_select"):
		_anim_tree["parameters/playback"].travel("Running")
	else:
		_anim_tree["parameters/playback"].travel("Idle")
	move_and_slide(v,Vector3.UP)





    

y is inverted in Godot. Your gravity points up. But that also means your character is not on the floor when code is run

Inces | 2022-08-24 12:15

:bust_in_silhouette: Reply From: SteveSmith

You would normally multiply by delta, not divide, but you don’t need to do this with move_and_slide() anyway. Then check your values, and check that your gravity is strong enough to overcome the root_motion.origin.