I’m making a truck and I want a beeping sound to play when you roll backwards. I want to use AssemblyLinearVelocity but I don’t know how to detect just the forward and backward movement on its own.
you can play around with the truck’s main center point’s velocity and using some input service
it may not work since im not good with keybind-related things but you could try making a script where if you hit S, a bool value which you can name goinBack is set to true and using if Truck.Body.Velocity > amountThatIsHighEnoughToCauseBeepingIGuess and goinBack.Value == true then beepbeep:Play()
hopefully it gives u some clues and requires some basic knowledge
But then if you were to brake without making a full stop/rolling backwards, the alarm would just play since Velocity doesn’t detect backwards or forwards movement. That’s why I want someone to help me with using AssemblyLinearVelocity.
You can get the vehicle’s velocity vector relative to its cframe and then compare the Z co-ordinate:
local relVel = Chassis.CFrame:VectorToObjectSpace(Chassis.AssemblyLinearVelocity)
if relVel.Z > 0 then
-- vehicle is going backwards
end
Perhaps have this run in a Changed event or a Heartbeat loop and make sure the sound doesn’t play again if it is already playing
yeah i added the input service for a reason, anyways the velocity statement is triggered when it reaches high speeds and naturally when u slow down aka letting go of the key, the velocity gets lower and lower till it doesnt meet the statement’s requirement