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

I am making a game and can someone help explain bodyvelocity to me?

Asked by 4 years ago

Can someone help explain bodyvelocity to me? I might use it in a space game im doing soon and I need some help.

0
why is ur reputaion so low? techingenius -82 — 4y
0
lol sean_thecoolman 189 — 4y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
4 years ago
Edited 4 years ago

So body velocities are an easy way to handle movement in a single direction at a time. The velocity is all you really need to know about in order to change the direction and speed of a part. It is made up of 2 components: Speed and direction. The direction is a unit vector (a vector3 that has been normalized) and the speed is just a single number that sets the speed of the part.

So lets say you want a part to move from pointA to pointB at a speed of 100 studs per second:

local Speed = 100
local p = Instance.new("Part")
local bv = Instance.new("BodyVelocity")
p.CFrame = CFrame.new(pointA,PointB)--it will spawn in the part at pointA looking at pointB
bv.Velocity = (pointB - pointA).Unit*Speed
bv.Parent = p
p.Parent = workspace

You subtract the starting position from the goal position and turn it into a unit vector using .Unit to get the direction, left alone, the part would be moving from pointA to pointB at 1 stud per second. So now that we have that, we can multiply it by the Speed to get the part moving in the direction you want to travel at the speed you want it to travel.

Also pointA and pointB would be Vector3 positions.

If you need further clarifications, just ask, if not, then mark this as the accepted answer.

Ad

Answer this question