05-10-2019, 09:41 PM
Hello, I have question about SplineController. I'm making a music arcade game like AudioSurf. I decided to use "50_EndlessRunner" scene as a start point and "RhythmTool" asset which allow to detect beats and onsets of music. RhythmTool divides song on frames (30 frames per second) and I decided to use frame value as position on spline to add objects (obstacles and powerups). It works good but problem is in Ship movement. Few days I tried to understand how to calculate Speed value of SplineController to move Ship in the rhythm of song. I found only 1 working solution is to set Speed = 0 and use Position parameter instead. I made own SplineController child class and in Update method I do this:
float nextPosition = rhythmTool.currentFrame - InfiniteTrack.Instance.lengthCut;
Position = Mathf.Lerp(Position, nextPosition, Time.deltaTime * 1000f);
"lengthCut" value is the total length of destroyed spline segments. I need to substract it because Spline is cutting when Ship achieves new CP point and Spline's initial position resets.
This code works, BUT OnControlReachedPoint event never called and therefore infinite spline is not infinite As I understand events work only when Controller moves using Speed value.
So my question is how I can calculate Speed to move Ship in rhythm of song or how I can use Position value together with events?
As I know from school, Speed = Distance / Time. Where Distance = nextPosition - Position, Time = rhythmTool.interpolation (time between current and next frame). But this formula not working...Maybe you can help, I hope....I just stuck on this. Thanks in advance.
float nextPosition = rhythmTool.currentFrame - InfiniteTrack.Instance.lengthCut;
Position = Mathf.Lerp(Position, nextPosition, Time.deltaTime * 1000f);
"lengthCut" value is the total length of destroyed spline segments. I need to substract it because Spline is cutting when Ship achieves new CP point and Spline's initial position resets.
This code works, BUT OnControlReachedPoint event never called and therefore infinite spline is not infinite As I understand events work only when Controller moves using Speed value.
So my question is how I can calculate Speed to move Ship in rhythm of song or how I can use Position value together with events?
As I know from school, Speed = Distance / Time. Where Distance = nextPosition - Position, Time = rhythmTool.interpolation (time between current and next frame). But this formula not working...Maybe you can help, I hope....I just stuck on this. Thanks in advance.