i basically have a rotating part moved by a hinge,that part is welded to a wheel so it can move around the axis.The problem is that since it can move freely I cant rely on RotVelocity. What would be the best way to measure the rotation speed of it?
Find a way to calculate how many degrees it has turned. This could be using orientation, or something else. Once you find how to get the current degree measurement, then the rest is simple. You just need to subtract the current rotation by the previous rotation, and you got your increment. Now, this would ideally be running in a Heartbeat loop, so divide it by DeltaTime
, and you got what you need.
Here’s an example:
-- Services --
local RunService = game:GetService("RunService")
-- Variables --
local RotatingPart: Part = workspace.Part -- The part that is rotating
local PreviousRotation = 0
-- Functions --
local function GetDegrees(Part)
-- Returns the current rotation (in degrees)
end
-- Scripting --
RunService.Heartbeat:Connect(function(DeltaTime)
local CurrentRotation = GetDegrees(RotatingPart)
local Difference = math.abs(CurrentRotation - PreviousRotation)
PreviousRotation = CurrentRotation
local Speed = Difference / DeltaTime -- The speed in Degrees Per Second (DPS)
print("The speed is: "..tostring(Speed).." DPS")
end)
Hopefully this helped you solve your problem.
The AssemblyAngularVelocity of a part tells you how fast its rotating. Its magnitude is the speed of rotation and its direction is the axis its rotating around.
that works really nice,thank you
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.