Name: Smooth Path
The Smooth Path package allows you to define a path of points, and have entities smoothly curve along those paths. The curves are calculated automatically, so all you need to do is set up the path points. The entity that follows the path must have a smoothPathFollowerScript on it, where you can define a path, speed, and rotation type.
Two example paths are provided, called SmoothPathExample_FollowTarget (where the follower faces towards the central target) and SmoothPathExample_RotateAlongPath (where the follower faces the direction it is moving along the path).
There is also a PathSpeedAdjuster script folder that you can attach to the User or Player template. Here, you can select a path follower to control, and it allows you to adjust the speed of the path follower by holding a button. Alternatively, you can set the speed of the path follower when it reaches different points along the path, by adjusting properties on the path points themselves (explained below).
Functions to use
These functions are on the smoothPathFollowerScript.
This will tell the smooth path follower to move along the path at its given speed. It can be called on server or client, but will only run if the “runOnClient” property is set to match where it’s being called. The “loop” argument tells the path follower whether to keep looping around the path. By default, it will run the path once.
This stops the path follower from moving. It will remain in position. It can be called on server or client, but will only run if the “runOnClient” property is set to match where it’s being called.
This stops the path follower using the stop function above, and then also returns it to the position and rotation of the first path point, ready to go again.
This assigns a new path for this path follower to follow. This could allow a set of paths to be used with decision points in between, and when the player makes a decision, you can use this function to set the next path to follow, and then call “Move” to move along the next path.
This sets the speed of this path follower. You can use this to speed up and slow down the path follower (see the “pathSpeedAdjuster” script in this package for an example). If used with EstimateTotalDistance() and GetDistance(), you can use this to have the path follower accelerate at the start of its path, and decelerate to a stop at the end, which is how the ghost train in the Dark Circus Hub works.
This will return a rough estimate of the total distance along the path, in cm. You can use this in conjunction with the GetDistance() function to work out how far along the path this follower is. Can be called on server or client.
Returns the distance this follower is along its path, in cm. Must be called in the same place as the path follower is moving (server or client) otherwise this will return nil.
Path point properties
Each point along the path has a “smoothPathPoint” script attached, where you can allow the point to adjust the path follower’s speed.
setSpeed - whether or not this point will set the path follower’s speed.
pointSpeed - the speed to set the path follower to at this point.
setSpeedSmooth - if ticked, the path follower will transition towards this speed, between the previous path point and this path point. If unticked, the path follower will instantly set this speed on reaching this path point.