Object Coordinates with timecode
Sorry if this has been covered elsewhere, I was not able to find an answer and I'm new to unity/visual studio.
I have list collection of coordinates for an object which has corresponding timecodes, small example: [{timecode = 0.0122676, x = -1.81340087228691f, y = 34.9939488172236f, z = 5.52542929662983f},{another},{another}, etc].
I have the object moving according to the coordinates, but the speed is incorrect and not realistic. How do I match the motion of the list according to the timecodes and make the motion smooth?
I greatly appreciate the help!
to understand you correctly: the object (gameobject) should move to one of these coordinates within the timecode given? Like "move to x,y,z in timecode"?
Yes, I am basically trying to accurately simulate the movement of an object from tracking data. I have to make sure it moves smoothly and at the correct speed. The tracking is based off of 30fps, if that helps. Also, there are 49 data coordinates in the list, so a little over a second and a half, I believe.
That's quite fast isn't it? I could think of something like this:
TimeCode[] timeCodeArray;
int timeCodeIndex = 1;
float slowDownFactor = 10f;
float slowedTime;
void Start(){
slowedTime = Time.time * slowDownFactor;
}
void Update(){
slowedTime += Time.time * slowDownFactor;
while(timeCodeIndex < timeCodeArray.Length
&& slowedTime > timeCodeArray[timeCodeIndex].timeCode){
timeCodeIndex++;
}
transform.position = (Vector3.Lerp(timeCodeArray[timeCodeIndex - 1].xyz, timeCodeArray[timeCodeIndex].xyz, (slowedTime timeCodeArray[timeCodeIndex - 1].timeCode) / timeCodeArray[timeCodeIndex].timeCode)
};
I just saw that the lerp code is wrong anyway. it should read something like: lerp(lastCoord, currentCoord, (slowedTime - lastTimecode) / (currentTimecode - lastTimecode))
am on mobile right now, real syntax would be a pain
Your answer
Follow this Question
Related Questions
How Do I modify speed to be slower? 2 Answers
How to make my powerup last for about five seconds then go back to normal? 3 Answers
How to Get Speed to Very Gradually Pick Up Over Time? 2 Answers
How to change FirstPerson Controller Speed OnTriggerEnter event for a certain amount of time? 0 Answers
Time delay enemy respawn 3 Answers