Please help with an animation logic problem

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
garcia1000
Prole
Posts: 34
Joined: Sat Nov 28, 2015 5:54 am

Please help with an animation logic problem

Post by garcia1000 »

Hello, I have attached a file showing my problem with an animation. It is basically several image files, with a body, a head, two arms, and a wand.

I created some parent/child relationship. So the arms and head are children of the body. The wand is child of an arm.

Then, I created two functions, one function is "move", which moves the image. This one is no problem. The other function is "rotate", which rotates the image about a pivot point. This is a problem at the moment.

When you run my file, you can press "s" to rotate the body, which moves all its attached children along with it. No problem so far. But then, try pressing "f" to rotate the head. The problem here is that the head's rotation is always the same, but it should be relative to the body.

Could you please take a look at the code and see what is wrong with the coding logic? Here is brief description of all the files:

animations.lua: the main code for the animation.
main.lua: very short, this should be self-explanatory.
middleclass.lua: this is from kikito
pic.lua: very short class for animations, mainly it just draws the images along the center of the image.
sandbox.lua: the controls for moving the animations.
tween.lua: this is from kikito too.
Attachments
Animation.love
(28.46 KiB) Downloaded 138 times
User avatar
Semicolon
Prole
Posts: 3
Joined: Tue Apr 04, 2017 5:34 pm

Re: Please help with an animation logic problem

Post by Semicolon »

Heya, interesting problem! I'm not sure if you're still looking for help with this, and I'm afraid I'm not advanced enough to find my way through the .love you provided (the libraries especially are beyond my comprehension) but I thought I'd try to help.

I've put together a simple .love with a rudimentary parent/child "Drawable object" system. Maybe it can serve as inspiration, at least?
parentChildAnimation.love
(20.01 KiB) Downloaded 145 times

The important bits are in Drawable.update and Drawable.draw. The gist of it is that every child object has a "pivot" and an "offset".
Pivot is the point around which the object rotates. (Relative to its center. In a 128x128 image, the top left corner would be x = -64, y = -64)
Offset is the point at which the pivot resides. (Relative to the pivot point of its parent)

Controls:
Q and E keys change the angle of the active object
WASD moves the offset of the active object (Has no effect on "body", since it isn't the child of anything. If you wanted to move it, you'd change its x/y position instead)
Right/Left arrow keys change which object is active
F12 toggles drawing the pivot points

Let me know if the code makes sense! I only added comments in a couple parts, but I tried to keep everything reasonably simple.
JoshGrams
Prole
Posts: 33
Joined: Sat May 27, 2017 10:58 am

Re: Please help with an animation logic problem

Post by JoshGrams »

I'm guessing you figured this out already, but the problem is that you're using a pivot point that is in world coordinates, not one that takes into account all of its ancestors' rotations.
garcia1000
Prole
Posts: 34
Joined: Sat Nov 28, 2015 5:54 am

Re: Please help with an animation logic problem

Post by garcia1000 »

Thanks for these replies Semicolon and JoshGrams. We solved it already and yes the problem was that the pivot point was anchored to the world coordinates and didn't take into account parent rotations.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 58 guests