Skip to main content
GameDev.net gamedev.net
🔒 Locked

float object up and down

Started by cebugdev Sep 22, 2019 at 7:28 AM 4 replies 3.7k views
Original Post
cebugdev
cebugdev

how to do floating physics, what is the calculation per frame,

by floating i do not mean water floating but hover/air floating where the object is bouncing up and down like say a floating/flying island.

Whats the per frame computation of it?


thank you in advance

pcmaster
pcmaster

For example using the sine or the cosine function.

position = base_position + ( amplitude * sin(speed * absolute_time) )

where base_position would be the point around which it'll oscilate, amplitude is how much plus/minus around it it will oscilate (sine and cosine operate on all real numbers and return values [-1; +1]), speed scales the 'animation' speed (when 1, it'll do 1 'loop' in 2PI seconds) and absolute_time is your system time, for example.


alvaro
alvaro
5 hours ago, cebugdev said:

[...] bouncing up and down like say a floating/flying island.

I don't think I've ever seen a floating/flying island. Can you point us to some reference video of what you are trying to achieve?

JohnnyCode
JohnnyCode

Do you want to achieve something like a spring joint in all three axises on an object? This will couse it to bounce when interacted with a force and returning to original position when force gets balanced off.

pcmaster
pcmaster

I think OP desires something like this:

395f354a7ebc081604f6e8e7d84d3998.gif

Note that you won't achieve exactly this with my solution, it'll be much more "fluid" but you can experiment with smoothstep for example.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.