How to make the number sine reach the limit in a certain time

Suppose the number in seconds is 5. In this way I want that with this = math.sin(tick() * number that you think should be multiplied taking into account the duration value 5).

The operation will be updated in a while loop, I want it to make the number that returns, if it is -1, then in the past 5 seconds it will be 1, and if it is 1, then in 5 seconds it will be -1, I want that for a swing animation that will last a certain time and I have to divide the time into certain parts, that’s why I have to do such a calculation

A sinusoidal function is generally defined as:
A * sin(2 * pi * f * x + phi) + C
Where:

  • A is amplitude
  • f is the frequency
  • x is the independent variable
  • phi is the phase shift
  • C is some constant vertical offset

In your case, the amplitude would be the number of choice, the independent variable would be time, and the constant vertical offset would be zero.

I can’t say what the frequency or the phase shift would be though because I don’t fully understand the request.

Here’s what I understand: you have some function f(t) that you are repeatedly calling, passing in the current elapsed time since the start of the animation t, in the while loop that gives you some value you will use for a swing animation.

But what I don’t understand is the values you expect at different points of the sine wave. Would you please describe what values you expect at different points of the wave, according to the attached image? All the capital letters are points on the sinusoidal wave I would like you to give an example of what the values should be (i.e., what time should that be and what value should that be)

2 Likes

In image A, I expect a value 0, B I expect a value 1, C I expect a value 0, D I expect a value -1 and e a value 0, the important thing is that from value A to B, it lasts a certain time in the same way that B to C, C to D and D to E

help me please please for please help me i need help

So based on what you said, the function given some time should look something like this since the amplitude would be 1 and the phase shift would be 0 and the frequency depends on the section time:

local sectionTime = -- time it takes to finish each section (e.g., A to B, B to C, etc.)

local function yourFunction(deltaTime: number): number
  return math.sin((math.pi * deltaTime) / (2 * sectionTime))
end
1 Like

DIOS TE BENDIGA ERES LA MEJOR PERSONA DEL MUNDO, HASTA MEJOR QUE CHAT GPT 4. BENDICIONES!!! lucky in all you like

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.