#How can one setup top down animations in Animation Player that rotate and move the player locally?

10 messages · Page 1 of 1 (latest)

ruby hedge
#

I encountered this problem in the recent wildjam, I have a player/enemy in topdown perspective and I want to quickly and visually create an animation. I have now managed to create a minimal setup/example that works (Pic provided) but it sounds way too complicated and I was wondering if there is a better way to implement this.

This is the problems and my thought process and solutions I came up with

  1. animating the position of the root node doesn't work because that's global coordinates, creating a sub node to animate fixed that.
  2. changing the player direction doesn't affect the repositioning that happens in animation player. I created a third node that allowed me to do that, I named the second one LocalRotation and the third one LocalPosition. if localRotation has 30 degree rotation (aka the player looks at 30 degrees) and an animation of localPosition moves by x=100 then that transform will be rotated as well since it's a child node of localRotation.
  3. Then certain things such as sprites shouldn't be rotated plainly (for example a 4 direction sprite only has 4 angles drawn) so once again created 2 more nodes, 1 for things that should get rotated and 1 for things that shouldn't, NoRotation constantly counter rotates.
  4. To keep the object from going through walls the collider also constantly has to update to the LocalPosition.position and everything gets re-zeroed after an animation gets canceled or finishes (for example LocalPosition = (10,0) -> (0,0) and root becomes (+10,0)). So this inserts a complexity of always looking after any animation and cleaning its changes in rotation and position (pic 2 provided). To be expected but I am also never able to use sprites in animations but rather change variables and create @tool scripts so that I can see the sprite changes during animations.

If only there was a way to make animations in local coordinates and with some rotation variable in mind..

#

well maybe a @tool that updates the player with move and slide and an animation that changes a velocity var should work too, thoughts?

ruby hedge
# gloomy estuary Here u go: https://www.youtube.com/watch?v=UYQfVx1EIW8

not really what I am asking, I want to create complex animations that involve a position change whilst still being able to preview them in animation player and prevent them from clipping through terrain. The game doesn't necessarily need to be top down, it could be crafting a complex attack in a side scroller that changes the velocity of an object.

the only real practical solution I have so far found (ignore the setup in the pic) is exporting a variable like animationVelocity and manipulating that in AnimationPlayer, then to preview it I can use a @tool editor only script that slip_and_slides or move_and_collides the object and resets position velocity and rotation on animation end and change.

narrow cedar
#

Hi there 😊,

Interesting approach. I recap what I understood: You want to be able to animate a game entity, where the animation is part of an actionable feature not just the visual set dressing of the game. Using no/low-code and having visual in-editor feedback while you develop said actionable feature.

#

Did I get this kind of right?

ruby hedge
#

Here is my @tool script so far:

@tool
extends Node

@export var target:CharacterBody2D
@export var animation_player:AnimationPlayer

func _process(delta):
    if not Engine.is_editor_hint() or target==null:
        return
        
    if(!animation_player.is_playing()):
        animationFinished("clear")
    target.velocity=target.Anim_Velocity
    target.move_and_slide()


func animationFinished(anim_name):
    if not Engine.is_editor_hint() or target==null:
        return
    target.Anim_Velocity=Vector2.ZERO
    target.position=Vector2.ZERO
    pass # Replace with function body.
#

and animationFinished is getting signalled by both animation changed and current animation changed

#

tbh this approach seems to work and requires no additional setup other than using 1 or 2 animation variables to move the player and a few restarts to get the @tool to start working, unless there are any recommendations I think I can mark this as solved.