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

Why won't the Velocity change and make the ball move?

Asked by 6 years ago

Right now I'm working on a golf game and I currently don't know why the ball doesn't actually move. This always works the first time I create and script the object but after the first test nothing works. IT'S FRUSTRATING!!!

local Ball = script.Parent
local AddVel = Vector3.new(75,150,0)

print("Hitting in 3 seconds")
wait(3)

Ball.Velocity = Ball.Velocity + AddVel
print("Hit")

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

The velocity property of parts can be a bit tricky to control sometimes, especially in unanchored parts. If you want to move the ball we can use something called a BodyMover , in this case BodyForce, which moves the part in world coordinates.

First let's make a force variable

local force = Vector3.new(75,150,0)

Next let's create the BodyForce instance and change its force

local bf = Instance.new("BodyForce")
bf.Force=force

Now let's put things together

local Ball = script.Parent
local force = Vector3.new(75,150,0)

local bf = Instance.new("BodyForce")
bf.Force=force

print("Hitting in 3 seconds")
wait(3)

bf.Parent=Ball
print("Hit")

Ad

Answer this question