How to do Acrobatics in Defold?

So, today I began to compile the LD42 entry into a complete game and have made good progress in it. Still when I was developing its player controller this ques came to my mind. - How do we do acrobatics, i.e. back/front flips in Defold? As far as I think, it will be combinations of rapid changes in angular speed, but am not able to make a complete logic out of it. Anyone plz help me solve this…
Thanks in advance :wink:

Does it suffice to simply play an animation of a back/front flip, while actually just doing a jump? Does the simulation of rotation need to take place?

1 Like

Yes, because the sprite kit I have lacks it. So, probably it is needed to play with the rotation

You can animate the euler.z property of a GO either to 360 or -360 if you want to do a simple rotation.

 go.animate(".", "euler.z", go.PLAYBACK_ONCE_FORWARD, 0.5, go.EASING_LINEAR)

You can set euler.z manually with

go.set(".", "euler.z", "90")

If you want to set the rotation angle manually and use radians you can use vmath.quat_rotation_z() to set the rotation around z.

local angle = vmath.vector3(1,0,0)
local rotation = vmath.quat_rotation_z(math.atan(angle.y, angle.x))
go.set_rotation(rotation)

Maybe I don’t understand what you want though. Do you want to rotate while also moving the character in an arc?

2 Likes

I wanted it to be something like mini militia, when you activate your jetpack and flip again and again. Even I am not sure how can I define that sort of movement, but the answer might be yes.

I looked at a video of that game and it does look like what you want can be done with the functions I mentioned. Try them out!

Yes , rotating the go and at the same time displacing it along X gives a perfect flip, but what I wanted is something different. In mini militia, when you press the left joystick and rotate it, it gives a perfect flip. I wanted to reproduce it. Since after trying to understand @britzl 'S multi touch example and failing again and again, I think I might need help in creating it.

Which example and what’s is it that you don’t understand?

Space shooter in Defold
This one. I was unable to understand that sin cos part where we handle movement of joystick

I created a picture:

We measure the distance from the touch point to the center position of the analog stick and calculate the angle/direction in which we dragged our finger. We use this angle to decide in which direction to move the ship. We must also visually move the analog stick, but we don’t want to position it on the touch point but instead limit it to the edge of the joypad (green dot in image). We get the sin and cos values of the angle. This gives us two values in the range -1.0 to 1.0. We multiply these by the radius of the joypad to get the amount we need to move the analog stick from the center to place it at the edge of the joypad.

4 Likes

Thanks a lot. I tried to understand the script many times to no avail, and you just cleared my doubts in a sec. I will try implementing this + @pkeod 's suggestion tomorrow and see what comes out of it.