Hi people, beginner programmer here.
I’m using the Unity Splines package for the first time I’m trying to Instantiate()
something on a specific point on a spline.
Hi people, beginner programmer here.
I’m using the Unity Splines package for the first time I’m trying to Instantiate()
something on a specific point on a spline.
There doesn’t seem to be a convenient, built-in method to do that.
I guess the best solution is to find a user-defined method that makes it easier for you.
First, read Venkify’s example. It’s a lot of code for something that should be much easier (posted on Apr 14, 2021):
https://forum.unity.com/threads/how-to-move-an-object-along-a-spline-spriteshape.837739/#post-7036966
Then check out the helper method that Brogan89 created (on the same page, last edited on Apr 2, 2023):
https://forum.unity.com/threads/how-to-move-an-object-along-a-spline-spriteshape.837739/#post-7747068
Brogan89’s method lets you do this:
Vector2 startPosition = spline.GetPoint(0.0f);
Vector2 midPosition = spline.GetPoint(0.5f);
Vector2 endPosition = spline.GetPoint(1.0f);
The spline
variable should be of the type Spline
or a type that is derived from the Spline
class, and of course it should be a reference to an existing spline.
I hope this helps.
Hi @Nerin ! Regarding your demand, You can have a look at the API documentation to check all the methods available to you but for your case, when creating a SplineContainer with splines you then have access to : mySplineContainer.Evaluate() method and that will give you the evaluated position, tangent (forward direction), and up of a spline point.
In your case you can do:
mySplineContainer.Evaluate(0.75f, out var position, out var tangent, out var up)
and you should have all the necessary information
© 2022 - 2024 — McMap. All rights reserved.