Feedback on rail grinding script idea

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.

  1. All the rails on the game map will be grouped together in a singular folder
  2. These rails will furthermore have their own folders, whose children are nodes placed along the rail as reference points for the grinding script
  3. 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
  1. The function connected will get the player’s character from the touch parameter
  2. 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
  1. Then the AlignOrientation will align the player with the node.
  2. 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.
  3. Grinding animation will play
  4. 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.

2 Likes

I actually have no idea how I’ll get the position of a node that aligns with the player’s LookVector. If anyone knows how, please reply