How could I tell if a Rotation Vector3 Value rapidly changes directions?

I am attempting to use the humanoid property, MoveDirection, to try to tell when a player rapidly changes the direction they are walking in at least an 110˚ angle. I do not really know how to tell if a Rotation Vector3’s X or Z rapidly changed at least 110˚ as I am not too experienced with programming with math. I read the documentation and somewhat know how to implement MoveDirection into this script. However, I just need to run a function when the Vector3’s X or Z changes within like .3 seconds by 110 in any direction. Thank you to whoever could be of help!

I can give you an idea of your problem and how you can solve it.

Let’s say the maximum rotation is about 10 vectors in less than 1ms.

so if vector 3 changes more than 20 either in X,Y,Z in less than 1ms

it would look like this

“if part.CFrame > vector3.new(0,20,0) then”

(The code is a visual example and does not work)

1 Like

I’m not sure I understand exactly what you mean, since you are talking about using the MoveDirection property, which has to do with the movement of the character relative to the 3D space. However, you talk about degrees - being a 110˚ angle - which is accessed not with the MoveDirection, but the LookVector.

So if you were talking about how to check the turn speed of a player in degrees, do the following;


Located in StarterPlayer → StarterCharacterScripts → LocalScript

local player = game.Players.LocalPlayer
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local prevCFrame = humanoidRootPart.CFrame
local WAIT_TIME = 0.3 --//The smaller the time, the narrower the time-window will be
local maxAngle = 110 --//Maximum angle difference before it triggers the condition

while task.wait(WAIT_TIME) do
	
	local angle = math.deg(math.acos(humanoidRootPart.CFrame.LookVector:Dot(prevCFrame.LookVector)))
	
	if angle >= maxAngle then
		print("Turning faster than 110 degrees;", angle) --//debugging purposes, remove if preferred
		--//Execute code here
	else
		print(angle) --//debugging purposes, remove if preferred
	end
	
	prevCFrame = humanoidRootPart.CFrame
	
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.