Limit speed of BodyPosition

So I am using BodyPosition to move parts around the workspace, but they go really fast in the middle of the movement. I need to limit the speed, and I’ve tried using MaxForce and such… I can’t get it to work…
(Sorry if wrong category)

It’s a bit odd that a BodyPosition is accelerating. Have you tried lowering P (the power) and increasing the D (damper)?

Are you using a script to manipulate the BodyPosition? Also, this would belong in #help-and-feedback:scripting-support

1 Like

I had assumed it wouldn’t go there since its not actually scripting related…
I’ll try changing the P and D values but I need it to not be too (can’t think of the word) tween-y… What I mean is accelerating at the start and decelerating at the end too long… I want it to accelerate for about 0.1 seconds, hit max speed, and at the end decelerate for 0.1 seconds.

No I am not using a script to manipulate it (other than set position once)

Personally, I (almost) always put the MaxForce to math.huge and control the speed using P and D. I found I have a lot more control over it like that.

I don’t have much information on your case but it looks like decreasing D would work.

I need it to not overshoot at all… What I want is it to stay at a constant speed, where tweens would be too inefficient (I believe) as there will be a lot of objects

In that case you should look at repeatedly setting the BodyPosition.Position a little more in the direction you’d like, until you reach your desired position.

I can’t exactly do that due to the way the script is set up. it’s very critically time based. I’ll try change it
EDIT: Nope… not possible and wont be because the parts are following the player. They stop when they have reached the player, they can’t have the position tweened to the player

I’m not sure if it’s possible in any other way, if it’s time based I’d advise tweening the CFrame or Position property of the part you’re trying to move.

I couldn’t do that either because it’s using magnitude to determine when to stop, and I’m having 300+ 2 part models moving at a time which would cause performance issues I believe

EDIT: I can use AlignPosition!

1 Like

You might get better results with a BodyVelocity. You’ll have to manually set the velocity to face towards the target though. It’d also make sense to make it slow down a bit when it gets close to the destination. Here’s an example script showing how it might be done:

local followerBodyVel = --- your body velocity
local targetPosition = --- some Vector3 world-space position

local targetSpeed = 20
local rampDistance = 20 --at 20 studs distance, speed is 100% of targetSpeed. At 1 studs distance, it's 1/rampDistance = 5%

game:GetService("RunService").Stepped:Connect(function( dt )
	local difference = (targetPosition - followerBodyVel.Parent.Position)
	local distance = difference.Magnitude
	local direction = difference.Unit

	local rampAmount = math.min(1, distance/rampDistance)

	followerBodyVel.Velocity = direction * targetSpeed * rampAmount
end)

EDIT: Or use an AlignPosition constraint :stuck_out_tongue: