# How do I start a sine or cos wave at a custom point in time?

ETGgames
Member, PRO Posts:

**189**
ETGgames
Member, PRO Posts: **189**

## Comments

12,822Do you mean the angle on which a sine function is operating ? (a sine wave doesn't have a rotation) ??

I'm not 100% what you are saying here, but this is how it works . . .

sin(angle)will give you the sine of whatever angle is in the brackets.189yes i mean the angle of the sine wave. if not, then can you tell me how to have counter clockwise interpolation of rotation

My Games:

https://itunes.apple.com/us/developer/ethan-sarif-kattan/id825823924

https://play.google.com/store/apps/developer?id=ETG+Ltd.

Website: https://etggames.com

12,822So what is the question then ? It's not clear what you are asking ?

If not what ?

Interpolation ? I thought you were using constrain ?

You can interpolate in a counterclockwise direction by simply interpolating to a positive value larger than the current rotation.

So if your actor's rotation is 0° then interpolating the rotation to (for example) 500° will make it rotate counterclockwise.

11,936@Socks, I think the question is related to forcing the result of a sin() function to initially be zero. For example, if game.Time is 12.999 when the scene begins and self.Rotation is constrained to a sin() function, how can the starting value of that function be zero?

I imagine the answer is to use a custom time (game.myTimer) starting at 0 -- possibly along with an offset value depending on the sin() function -- and counting up. But you may have a better suggestion.

New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User

4,956If you want it to be 0 when you start the scene, just use self.Time.

If you want to start at, say, where it would be when time = 12, just do self.Time+12.

If you want to start it at 0 but at a time triggered at some point after the scene start, just make a real self attribute and change it to self.Time when you want the sin() to start, and then subtract it from self.Time (or game.Time if you use that) in your equation.

Contact me for custom work - Expert GS developer with 11 years of GS experience - Skype: armelline.support

12,822Ah! I see, yes that makes sense.

I'm still not 100% sure what's need, but assuming this is for an actor that is travelling in an orbit in a CCW direction - and needs to always start at 0° (or any specific angle) - then there are couple of very straightforward methods that avoid self.time and game.time's habit of starting before you get to the party.

Method 1:

main actor

--Constrain X to radius * cos (self.rotation) + origin

--Constrain Y to radius * sin (self.rotation) + origin

--Rotate behaviour (CCW)

With this method you can trigger the Rotate behaviour however you like - and whenever you like - and if you want a specific start angle simply point the actor to the angle you want the orbit to start at.

. . . . . . . .

Method 2: (basically the same method but with more control)

main actor

--Constrain X to radius * cos (controller.rotation) + origin

--Constrain Y to radius * sin (controller.rotation) + origin

--Constrain R to controller.rotation

controller actor

--Rotate behaviour (CCW)

With this method you can also trigger the Rotate behaviour (of the controller) however you like - and whenever you like - and if you want a specific start angle simply point the controller to the angle you want the orbit to start at . . you can also ramp up the speed of the orbit by interpolating the angluar rotation of the controller, introduce angular drag, go into reverse and many other things that would be fiendishly difficult if you were using game.time/self.time for the angle.

12,822Method 1: (Simple)

12,822Method 2: (More control)