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

Part not able to be knocked down after being tweened?

Asked by 1 year ago

I have bowling pins that are being tweened up and down to give it the effect that it's resetting. After the first time the player throws the ball, the pins are not able to be knocked down what so ever. I have check for welds and there are none, I have checked if it's unanchored and it is. Any help would be appreciated.

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

Solution

It's because the ball doesn't move by itself (in physics mechanics). What you need to do is use BasePart.AssemblyLinearVelocity by setting it as a directional vector towards the target.

Example (How to Use It)

Let's say you have a Model called Pins containing the pin meshes, and a ball part in workspace.

You want the ball to go to the pins after 5 seconds. To get the directional vector from the ball to the pins, you can subtract the position of the Pins model and the ball, then get the unit of it.

local Pins = workspace.Pins
local Ball = workspace.Ball

local pinsCFrame, pinsSize = Pins:GetBoundingBox()
local pinsPos = pinsCFrame.Position

local ballPos = ball.Position
local fromBallToPins = (pinsPos - ballPos).Unit

Now we can use this to set the velocity.

task.delay(5, function()
    Ball.AssemblyLinearVelocity = fromBallToPins
end)

But wait! If you try this out, you will notice that the ball only moved slightly! If you want it to move more, you can multiply it by the distance of you want it to travel or the speed/power you want to force move the part.

task.delay(5, function()
    Ball.AssemblyLinearVelocity = fromBallToPins * 30
end)

And now you're done! The final script should look like this:

local Pins = workspace.Pins
local Ball = workspace.Ball

local pinsCFrame, pinsSize = Pins:GetBoundingBox()
local pinsPos = pinsCFrame.Position

local ballPos = Ball.Position
local fromBallToPins = (pinsPos - ballPos).Unit

task.delay(5, function()
    Ball.AssemblyLinearVelocity = fromBallToPins * 30
end)

https://gyazo.com/159c26182f70d29d9f492c5785795c36

Alternatives

If you want to use any alternatives other than this method, you can use the Mover Constraints.

Ad

Answer this question