Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I reduce the movement of this part when it reaches the location?

Asked by 7 years ago

(rpet is a brick in workspace) (base is a part that is welded to the character)

My issue is once it reaches the location it moves too much heres a gif of it:

https://gyazo.com/e1b388ecc42085c64322a8ff009d7692

what I need is for it to move a bit but not that much how would I do that?


function MoveBook(pet, mode) local character = game.Players.LocalPlayer.Character local rpet = workspace["Book1"] local rmode = mode local inc = .7 if mode == true then -- if this is true then make book float local base = character[id.."A"] local dir = CFrame.new(rpet.Position, base.Position).lookVector print(dir) for i = 0,10,2 do rpet.CFrame = rpet.CFrame + (dir * inc) wait(0.05) end else local base = character["Left Leg"] local dir = CFrame.new(rpet.Position, base.Position).lookVector print(dir) for i = 0,5,1 do rpet.CFrame = rpet.CFrame + (dir * inc) wait(0.05) end end end while wait() do MoveBook("Book1", true) end

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago
Edited 7 years ago

I'm not sure why it doesn't seem to be going in the right direction, but I think I have a solution for your problem. Your "inc" is constantly 0.7, but it looks like you want this to be smaller when the pet gets close so it's doesn't go crazy. So you should make inc depend on the distance.

You could simply take the smaller value of either default inc or the distance divided by a large number. Distance being (base.Position-rpet.Position).magnitude

So at the start of the function, instead of this : local inc = .7 , do this:

local inc = math.min(0.7 , (base.Position-rpet.Position).magnitude/30)

where 30 is whatever you want.

Hope I helped!

Ad

Answer this question