Using sine to convey a swaying motion?

Blitz3D Forums/Blitz3D Programming/Using sine to convey a swaying motion?

Cubed Inc.(Posted 2012) [#1]
How do you convey a swaying, or pendulum like motion using Sin()?


Matty(Posted 2012) [#2]
Set the position, x,y or z based on a calculation such as:

position = offset + length * Sin(angle)

and simply change the angle each frame slightly...


Kryzon(Posted 2012) [#3]
You can also use it to modulate an 'angle offset' that you apply to the pivot of the pendulum.

[bbcode]
Const ROT_ANGLE# = 30.0

[...]

RotateEntity pendulumPivot, 0, 0, (Sin(angle) * ROT_ANGLE)

;Pendulum will swing from -30 to 30.
[/bbcode]


Cubed Inc.(Posted 2012) [#4]
What do you mean by changing the angle by each frame slightly? You want me to set up a flag where the angle of the pendulum changes from 30 to -30 after a certain amount of time, or am I misunderstanding the whole thing?


Adam Novagen(Posted 2012) [#5]
You're only half-misunderstanding. Open this example, it's in the B3D docs for Sin() and Cos():



Hold down one of the arrow keys and watch the green (cos) line. You'll notice that although angle# increases (or decreases, depending on which button you press) at a steady, ongoing rate, the green line will "swing" side to side in a perfect pendulum motion. I can't quite put it into clear words, but if you look closely at this example and what happens to the Sin() and Cos() lines you should be able to figure it out: sine and cosine "undulate" while a circular angle increases or decreases.

Last edited 2012