Hello!
I wondered if anyone has a more efficient way of making an object 'hover' or 'float' than the current plan of using animation frames.
The objects are static, and only really need to move up a couple of pixels, then down a couple of pixels, in an endless loop. I figured animation could solve it, but it feels like a waste of space to keep duplicating sprites and shifting them up/down.
I'm still getting the hang of AGS, but perhaps there's a bit of math or a tween that could take care of it?
Thank you very much!
You can use a sine wave for this:
float angle;
function repeatedly_execute_always {
angle += 0.03;
if (angle > Maths.PI * 2.0) angle -= Maths.PI * 2.0;
oHoverboard.Y = 120 + FloatToInt(Maths.Sin(angle) * 10.0, eRoundNearest);
}
(Just add this to your room script and adjust the object's script name and initial y coordinate of 120.)
Woah, that is next level math! Thank you very much, this is such a cool solution and it will certainly help me get into the numeric side of animation. I can't wait to try it out! Gracias!