hello! as part of my game, the player will be able to grind on rails as part of their base movement. however, I’m stuck trying to find a way to actually script it. here’s my general idea of it so far.
- All the rails on the game map will be grouped together in a singular folder
- These rails will furthermore have their own folders, whose children are nodes placed along the rail as reference points for the grinding script
- A for loop will be running constantly to see if a character hits a rail. something like this
for _, Rail in Rails:GetChildren() do
Rail.Touched:Connect(function(touch)
end)
end
- The function connected will get the player’s character from the touch parameter
- AlignOrientation, using its LookAtPosition property, will be used to get the position of a node that satisfies these 2 requirements
- Is located closest to the player
- Player’s LookVector is in line with the node
- Then the AlignOrientation will align the player with the node.
- LinearVelocity will be used to propel the player. I chose this over TweenService so I have easy access to their momentum and don’t have to make some complex formula just to calculate the TweenInfo duration.
- Grinding animation will play
- When the player hits a node located on the end of the rail, I’ll run a function with logic that stops all of the physics and the animations.
Pros:
- Easy manipulation of player momentum
- Easy to build off of.
- Theoretically, can allow grinding upside down!
Cons:
- Probably really performance intensive. Lots of Touched loops happening at the same time will probably cause strain on computers. I’m not sure if I want this to be a server or client script either.
If I missed anything, please add your feedback. This is my first big project as a scripter since I started in November, so I want to make it the best it can be.