Hi! So I'm working on overhauling the battle-gameplay of something I've been working on, and to put it short, the player will, from time to time, have free movement of 3 pre-defined "zones." An "A-Zone," "B-Zone," and you can guess what the third zone is called.
I've chalked up a couple ideas, one that uses Humanoid:MoveToPart, others that use BodyVelocity, others that use an invisible part pushing them / stopping them... and I've tried using the BodyVelocity, because it allows for me to easily adjust the speed, direction, and also doesn't include these invisible parts all over. It's simple and efficient.
Anywho, I've been working on a segment of script that is activated via function when the command-key for moving from zones is activated. It's using a simple unanchored part with the same dimensions as the players legs (minus height) so I can figure out how to center it perfectly in that zone. Zones will be visible, so that does need to be a thing. The script activates the body velocity, and then stops it at the perfect time.
My first idea of stopping the body velocity at the right time was a simple wait(). I'd activate it, and then trial-and-error through all the wait times until I got the one that provided me with the perfect centered position.
Keep in mind, the BodyVelocity is set to (0, 0, 70) when they move from zones. This way it's quick and fast-paced, necessary for some fights and the enemy's attacks.
So, the code is simple for this:
script.Parent.BodyVelocity.Velocity = Vector3.new(0, 0, 70)
wait(n)
script.Parent.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
Then I tested this script. After some testing, I realized that even if I had the wait times the same between both runs (runs so I could just see it in action without having to load my player in first to save time), the part would stop at different points. I looked it up and read that it's possible that wait() commands have small variations in their delays when ran multiple times. Since it was a high speed part and I needed precision, this was not ideal. The delay variation was not the best since it moved fast, so any small variation = very noticeable change in end position.
My next idea was stopping it just as it touched the part.
script.Parent.BodyVelocity.Velocity = Vector3.new(0, 0, 70)
script.Parent.Touched:Connect(function(touch)
if touch == game.Workspace.ZoneATarget then
script.Parent.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
end
end)
Also didn't work. The part was stopping after the initial touch (roughly 0.75 studs.) I tried adjusting the part size but it still stopped at the same point somehow.
So, what do I do?

1 comment
Use cframe lerp or make an invisible channel with cancollide on to force the player to move in the direction you set