Sensing part vibration

Hi, there. I’m currently experimenting with Roblox physics and I’m making a washing machine using Roblox physics in Roblox. Something came up to my mind, which had me wondering if it was possible at all. Is it possible for a regular script to sense the level of vibration or print it? I’m wondering since I wanted to script vibration sensors on the washing machine I’m working on. Any help would be appreciated. Thanks!

A way to sense the level of vibration would be to detect changes in the acceleration of the assembly (possible angular acceleration too).

Here is an example:

local sensorPart = script.Parent

local RunService = game:GetService("RunService")
--local threshold = 0.2 -- IDK, put some value here. Probably will need some testing

local lastVelocity = Vector3.new(0,0,0)
local lastAcceleration = Vector3.new(0,0,0)

RunService.Heartbeat:Connect(function(timeChange)
    local currentVelocity = sensorPart:GetVelocityAtPosition(sensorPart.Position)
    local velocityChange = currentVelocity - lastVelocity
    local currentAcceleration = velocityChange / timeChange
    local accelerationChange = currentAcceleration - lastAcceleration
    
    local currentJerk = accelerationChange.magnitude / timeChange
    --if currentJerk > threshold then
    print("Estimated jerk = "..currentJerk)
    --end

    lastVelocity = currentVelocity
    lastAcceleration = currentAcceleration
end)

This code finds the jerk, which isn’t exactly vibration, since vibration isn’t really a super specific thing (at least, the physics definition and the definition that everyone uses are different). Jerk should be pretty close to vibration though.

I don’t think there are other ways to detect vibration, but it depends what you’re trying to detect.

2 Likes

Thanks a lot! This will come in handy. :slight_smile:

1 Like