Smoothly increasing speed/amplitude of a Sine wave
I have a game where the main target is an actor that is constrained in the Y axis to a Sine wave.
I would like, as the game goes on, to increase the difficulty of hitting the target by smoothly increasing the speed of the wave and also its amplitude. I know which parts of the equation are responsible for these changes and have them set as global attributes, but if I change them when other rules trigger then the target seems to jerk and 'reset' it's position.
I'm guessing I'd need to change those settings when the wave is 'in the middle of its travel' and the Sine result is at 0, to get the smoothest transitions.
Any ideas how to do this? I've tried a few by constraining an attribute to the wave's value but it doesn't quite seem to work for me... think I'm missing something obvious but I just can't see it.
Cheers
Comments
Can you show us the code you are trying to fix ?
OK, here are the rules
https://www.dropbox.com/s/otgozlof2ji7ez4/rules.jpg?dl=0
So I am constraining my Y position to the equation:
where 476 is the initial height up screen and TargetsAmplitude & TargetsWaveSpeed are global attributes.
Then I constrain a second attribute self.SineValue to the above function minus the 476 so it just goes from -'value' through 0 to +'value' - 'value' equals the TargetsAmplitude attribute.
Finally I have a rule that checks to see if the self.SineValue is 0 (we are in the middle of the sine 'wave') and that the linear velocity of Y is positive (we are going up) and at that point I want to change the game.TargetsWaveSpeed.
But a display text showing the game.TargetWaveSpeed shows that it doesn't increase as hoped.
Any ideas?
@MattSoden
I think the problem is big infrequent changes. You can either increase the speed and amplitude slowly over time, for example:
constrain attribute speed to speed + 0.05
Or if you want it to change less often, you'll need to have an attribute instead of self.time, and set that attribute to a new value so that the actor doesn't jump.
Thanks @Manto I'll take a look when I have a few hours again.
I think I'll have to do one cycle of the Sine wave at a time, then update the settings, then go again, rather than trying to keep it tied to self.time.
I also had a mistake/issue when checking on linear.velocity.Y as because the actor's position is constrained to it's Y value, there is no true linear.velocity.Y to check against.
Not sure I followed all that, I would just do it in a single constrain behaviour, have the amplitude grow using self.time and the angle accelerating, again using something like self.time, so for example:
Constrain Y to . . . (self.Time * 20) * sin ( self.Time * self.Time * self.Time ) + 476
Obviously these values are pretty arbitrary, probably nothing like what you want, but it should give you the basic idea, cubing self.time for the angle accelerates quickly so you might experiment with some other way of increasing a value, for example you could have a separate attribute that is being interpolated and use this for the angle.
Just tried the above equation out, it works ok, it's a bit crazy but like I say the values are just thrown in you'd need to adjust them to your needs, file attached:
This is generally how I approach this sort of thing.
Whoa... That's like some self.Time inception. Mind=blown.
Follow us: Twitter - Website
Attached is a second approach, interpolating the amplitude and speed values separately, like this:
Constrain Y to A * sin ( S ) +476
Interpolate A from start to target
Interpolate S from start to target
File attached:
Be very very careful with time cubes, I know people who've been badly injured playing with this stuff.
Thanks @Socks and all, I have this running nicely now.
Now onto endgame programming and an instructions page...