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

How can I get a brick's velocity in a specific direction?[I figured it out]

Asked by 9 years ago

Ok, let's say I had a brick that was moving diagonally across the X and Z axis, but it was facing north the whole time. How would I determine the velocity of the direction that the brick is facing? Sorry if this question sounds a bit confusing

2 answers

Log in to vote
2
Answered by 9 years ago

Nevermind, I figured it out. In case anyone was wondering the same question too, I'll post my solution:

local Part = script.Parent

function GetVecAng(A,B)
    return math.acos( A:Dot(B) / ( A.magnitude * B.magnitude ) )
end

while true do
    local LookV = Part.CFrame.lookVector
    local VelocityUnit = Part.Velocity.unit
    local AngleBetween = math.min( GetVecAng(LookV,VelocityUnit) , math.pi / 2)
    local LookVelocity = ( math.pi / 2 - AngleBetween ) * ( 2 / math.pi ) * Part.Velocity
    print(LookVelocity)
    wait()  
end
1
Nice job. +1 wjs3456 90 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Do you want to determine it in game?? Or in studio?

0
I don't think it really matters where I want to determine it, but I want to determine it in studio TurboFusion 1821 — 9y

Answer this question