#sound playing on crash.

49 messages · Page 1 of 1 (latest)

shadow rock
#

could you give me edit i can help

meager kindleBOT
#

studio** You are now Level 5! **studio

tame tendon
shadow rock
#

ok

signal current
#

why not use .Touched instead of trying to calculate a sudden stop based on velocity? If you want to keep your velocity method, i think your logic for hasNegativeImpact could be wrong, or quite possibly how you're not using velocityChange at all.

shadow rock
#

lete me see

tame tendon
meager kindleBOT
#

studio** You are now Level 2! **studio

shadow rock
#

this should fix it local character = script.Parent
local RunService = game:GetService("RunService")
local humanoidRootPart = character:WaitForChild("Head")
local humanoid = character:WaitForChild("Humanoid")
local sound = character:FindFirstChild("ImpactSound") or Instance.new("Sound")
sound.Name = "ImpactSound"
sound.SoundId = "rbxassetid://8595980577"
sound.Volume = 1
sound.Looped = false
sound.Parent = character

local lastVelocity = Vector3.new()
local wallImpactThreshold = 20
local lastPlayTime = 0

RunService.Heartbeat:Connect(function()
local velocity = humanoidRootPart.Velocity
local velocityChange = (velocity - lastVelocity).Magnitude
local hasSignificantHorizontalImpact = (lastVelocity.X > 0 and velocity.X < 0) or
(lastVelocity.X < 0 and velocity.X > 0) or
(lastVelocity.Z > 0 and velocity.Z < 0) or
(lastVelocity.Z < 0 and velocity.Z > 0)

-- Ignore impacts where the velocity change is mostly vertical (Y-axis)
local horizontalChange = Vector3.new(velocity.X - lastVelocity.X, 0, velocity.Z - lastVelocity.Z).Magnitude
local verticalChange = math.abs(velocity.Y - lastVelocity.Y)

if horizontalChange > verticalChange and velocityChange > wallImpactThreshold and hasSignificantHorizontalImpact and tick() - lastPlayTime > 0.5 then
    sound:Play()
    lastPlayTime = tick()
end

lastVelocity = velocity

end)

#

i edit it for you in my studio

#

for auto correct lol

tame tendon
#

did you just use chatgpt

shadow rock
#

no

#

what makes you think that

tame tendon
#

you didnt even put in a character variable

shadow rock
#

mb

#

1 sec

#

ill fix it

#

lol

tame tendon
#

no need

shadow rock
#

i forgot to send the top part

signal current
tame tendon
#

and also

#

the exposed parts

#

the edge here

#

if i crash into it

#

it should make the sound

#

but if i use tag and consider that part a ground

#

hitting the edge wont make the sound

signal current
tame tendon
#

suprisingly @shadow rock

#

your code does seem to work well

shadow rock
#

oh it worked

#

nice

#

thanks

tame tendon
#

no let me see what you did with raycast

shadow rock
#
-- / Pre fabs PluginDecember 15, 2024 3:40 AM \ --     
local ReplicatedStorage = game:GetService('ReplicatedStorage') 
local RunService = game:GetService('RunService')
local ServerScriptService = game:GetService('ServerScriptService') 
local Players = game:GetService('Players')

local character = script.Parent
local RunService = game:GetService("RunService")
local humanoidRootPart = character:WaitForChild("Head")
local humanoid = character:WaitForChild("Humanoid")
local sound = character:FindFirstChild("ImpactSound") or Instance.new("Sound")
sound.Name = "ImpactSound"
sound.SoundId = "rbxassetid://8595980577"
sound.Volume = 1
sound.Looped = false
sound.Parent = character

local lastVelocity = Vector3.new()
local wallImpactThreshold = 20
local lastPlayTime = 0

local function isWall(hit)
    if not hit then return false end
    local normal = hit.Normal

    return math.abs(normal.Y) < 0.5
end

RunService.Heartbeat:Connect(function()
    local velocity = humanoidRootPart.Velocity
    local velocityChange = (velocity - lastVelocity).Magnitude

    if velocityChange > wallImpactThreshold and tick() - lastPlayTime > 0.5 then
        -- Perform a raycast in the direction of movement
        local rayOrigin = humanoidRootPart.Position
        local rayDirection = velocity.Unit * 2
        local raycastParams = RaycastParams.new()
        raycastParams.FilterDescendantsInstances = {character}
        raycastParams.FilterType = enum.RaycastFilterType.Blacklist

        local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

        if raycastResult and isWall(raycastResult) then
            sound:Play()
            lastPlayTime = tick()
        end
    end

    lastVelocity = velocity
end)

#

here

#

idk if it works

signal current
#

yeah that kinda leaves you with the velocity calculation. another way still is to use touched and use a raycast to decide if the surface being touched is facing a certain direction, namely vector3.up

shadow rock
#

cant rlly test tell me if it works if you want to

shadow rock
#

also i made a plugin it can be very usefull if you wanna see it

shadow rock