Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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 comment

1

Nice job. +1

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

1 comment

0

I don't think it really matters where I want to determine it, but I want to determine it in studio

This discussion is preserved as it was. New answers, comments, and votes are closed.