• 2D
  • 2D workflow. Animating center of sprites

Hi all

I'm new to Godot so I decided to make this a discussion rather than a question because I have one question but the rest is asking for opinions.

A super quick background on me: I come from Unity and I'm somewhat experienced with it but I'm tired of fighting it to make 2D games. I was (am) working on a grid platformer (some people call these cinematic platformers but I kind of dislike this term) when I finally had enough of that workflow. So here I am.

My most immediate concern (that I couldn't google an answer) is whether one can keyframe the center of a sprite. Unity calls this center 'pivot'. In Godot I think the term pivot is for rotations but it might also be used as center, I'm not sure. The reason I need to do this is because in a grid platformer the player is always on a grid, and what gives the illusion of movement is the animation. But it's still good practice to animate the character standing in place otherwise the spritesheet will end up huge and mostly empty space. Hence I need to animate the center of the sprite.

It is my understanding that Godot is very 2D friendly. Spatial units are actually pixels and whatnot. Can the same be said about frame-by-frame animation? this discrete approach was also problematic in Unity, as it's meant for continuous time approximation. For instance, I want to move the character one unit to the side before rendering the first frame of animation of idle state but after the last frame of animation of climbup state. I was cursing every deity ever conceived trying to find a way to do that with mecanim.

Judging by this very little information I've given, does trying Godot sounds like a reasonable move for me?

You can animate any property of a node (your animated Sprite would be a node), including the Sprite's offset from its origin. You can set your individual tracks to animate either continuously (smooth between keyframes) or discretely(snap at keyframes). Godot 2D should be very well-suited to making a grid platformer!

Now I'm super excited! I'll enjoy learning how to work with Godot.

Thanks :D

8 days later

Hey. It's me again.

So things are going nicely. I thought it would take longer to wrap my head around Godot's unusual architecture but it's surprisingly intuitive and neat.

Anyway, I ran into an issue and it fits this topic so I'm restarting it. I want to flip a sprite! that's simple enough with flip_h variable, but I'm also animating offset and I want that flipped as well. In a 3D environment this is easily achieved by rotating around z. But here I have no idea what to do. There must be a simpler way than duplicating all animations or altering keyframe values from script.

Can I animate my own parameters? I couldn't find any tutorial exposing script variables in the inspector, which would allow me to animate it. This could work for me as I expose a vector of my own and offset the sprite myself the way I need it.

edit: Just found out about export var. So that works. Still not ideal though, as I lose the visual reference when animating. So I'm still looking for a solution to this.

edit 2: OK! I got this. Make the sprite a child of a node2D and change x scale to -1. The local offset happens on the sprite but after the animation is done and you want to commit that offset to the sprite, change the node2D's position, not the sprite's.