Posts: 64
Threads: 11
Joined: Dec 2019
Hi, again.
As I was working, I checked the "align to spline" action a little bit closer. This thing does pretty much what the controller script does. So I thought why not use this instead of the controller script. Since cutting out scripts would make timings easier, especially if I want to change speed or position of objects on the spline, why not try this instead? So I have 2 questions regarding this.
1. How do I calculate the speed? If I used a controller set to absolute position and its speed is X with fixed update, how far should I move the object along the spline per frame to get the same result?
2. How do I transform the speed to Unitys transform? If I want to move the object off the spline but still keep the same speed it had on it, how do I calculate that?
Posts: 2,113
Threads: 92
Joined: Jun 2017
Hi
1- This formula should do it: position = speed * elapsed time. In a per frame logic, you will move the position by speed * time.deltaTime every frame.
2- Same as above, since you are using absolute position and speed, the speed is in m/s. If you were using relative speed, then you would have to multiply the speed by the length of the spline.
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 64
Threads: 11
Joined: Dec 2019
Posts: 64
Threads: 11
Joined: Dec 2019
There's one more thing I just realized that I can't easily visualize (due to bad math skillz). The spline slightly changes its length each frame, so I guess that would mean, even if the speed is the same, that the object travels a slightly different distance each frame if you measure its global position.
Is this a correct assumption and how should I offset the position each frame if so? All I care about is that the objects on the spline move the same world distance each frame, not the same distance on the spline.
Posts: 2,113
Threads: 92
Joined: Jun 2017
When setting the Movement Mode of the controller to Absolute, the speed is interpreted as a distance in meters (or Unity distance unit if your project considers it to be different than meters)
If Movement Mode is set to Relative, then a speed of 1 means that the controller travels a whole spline length per second.
The problem you describe is to be considered only when Movement Mode is set to Relative, which is not your case. So you don't have to worry about.
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 64
Threads: 11
Joined: Dec 2019
I'm not using the controller but the Playmaker action, but I guess they work the same. Thanks for the clarification. It was useful.
Posts: 2,113
Threads: 92
Joined: Jun 2017
(01-20-2021, 08:43 PM)Lupp_ Wrote: I'm not using the controller but the Playmaker action
Sorry, forgot about that. Yeah use the Position Mode then.
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.