Kinematic Body 2D and AnimationPlayer

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

Hi, Striker again, i’m doing a project, a kind of plataformer, today i was making my player sprite when, in my mind, i started to remember reading or listening something about character rigging and i started to think, what if, i make my character in separated parts and then rig him in the engine, that would save me so much time on animating each frame and putting it together, no only that but the quality would be so much diferent between rigging and animating each frame.

i don’t really know what to do, i already made the character rig, godot has a documentation about that, but when i make any animation, my character goes from playable to static while playing the animation, anyone knows what i need to do to make this work, or if there is some other way to do this?

What do you mean by “goes from playable to static”? Playing an animation and moving should be two completely separate things.

kidscancode | 2019-03-22 17:02

when i add the code $“animation_name”) to the script of the character it will stop acting like a kinematic body 2D and will be stuck at the same location he is on the player scene, this player scene is instanced on my level scene, my level scene only have the player and a super simple tileset that i made with the godot icon so i could have a ground where the player can stay, the player scene in the other hand have the root as a kinematicbody2D, a lot of sprites rigged to form the player body, a collision2D, a Camera2D and the AnimationPlayer.

StrikerSVX | 2019-03-22 19:49

You’ll have to include more about your setup - node structure, animation, and movement code. Generally speaking, if your animation is affecting the position property, then it’s going to be affecting movement. You shouldn’t be keyframing the body’s position, only those of its children (the rig). Also, if you’re continually calling play(), you’ll be restarting the animation every frame, so it’s not going to work.

kidscancode | 2019-03-22 20:19

What can i say more?


Node (root)
---- Tilemap
---- Animation (instanced)

Player (root, KinematicBody2D) has Script.
---- Sprites
---- Hib (Sprite)
-------- Sprites
-------- Torso (Sprite)
------------ RemoteTransform2D’s
------------ More Sprites
------------ Some Positions2D
-------- AnimationPlayer
-------- ColisionShape2D
-------- Camera2D

(is organized the same way that the tutorial on godot about rigging is.)
Cutout animation — Godot Engine (3.0) documentation in English

Player Script:

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 20
const MAX_SPEED = 250
const JUMP_HEIGHT = -550
var direction = Vector2(DIRECTION_RIGHT, 1)

var motion = Vector2()

func set_direction(hor_direction):
	if hor_direction == 0:
		hor_direction = DIRECTION_RIGHT
	var hor_dir_mod = hor_direction / abs(hor_direction)
	apply_scale(Vector2(hor_dir_mod * direction.x, 1))
	direction = Vector2(hor_dir_mod, direction.y)

func _physics_process(delta):
	motion.y += GRAVITY
	var friction = false
	if Input.is_action_pressed("ui_right"):
		motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
	elif Input.is_action_pressed("ui_left"):
		motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
		friction = true
	if is_on_floor():
		if Input.is_action_pressed("ui_up"):
			motion.y = JUMP_HEIGHT
		if friction == true:
			motion.x = lerp(motion.x, 0, 0.2)
		if friction == true:
			motion.x = lerp(motion.x, 0, 0.05)
	motion = move_and_slide(motion, UP)

i still a newbie but i have improved a lot since my first question about godot was answered.

StrikerSVX | 2019-03-22 21:25