What do you want to achieve? Keep it simple and clear!
im trying to achieve a Half-Life 1 gib physics
What is the issue? Include screenshots / videos if possible!
The gib wont bounce
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
ive tried changing the rotation that it raycasts in which it is because its pointing down
Extra Details: I have papers for plans on how it should work (my handwriting is kind of bad so ima just put it on here in plain text)
“When no sideways velocity then if on ground then bounce and set orientation to a random rotation”
local gib = script.Parent
local RunService = game:GetService("RunService")
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {}
RunService.Heartbeat:Connect(function()
gib.Position = gib.Position + gib.Vel.Value
gib.Vel.Value = Vector3.new(gib.Vel.Value.X * 0.9,gib.Vel.Value.Y - 0.2,gib.Vel.Value.Z * 0.9)
local raycastResult = workspace:Raycast(gib.Position,Vector3.new(-90,0,0) * ((gib.Size.Y / 2) + 0.5), raycastParams)
if raycastResult then
print("Bounce")
gib.Position = gib.Position + Vector3.new(0,gib.Vel.Value.Y,0)
gib.Vel.Value = Vector3.new(gib.Vel.Value.X,gib.Vel.Value.Y * -0.7,gib.Vel.Value.Z)
gib.Orientation = Vector3.new(math.random(-360,360),math.random(-360,360),math.random(-360,360))
end
end)
I fixed it by using a CFrame to rotate the raycast so yay HL1 gib physics!
Heres the script if anyone wants it (you need to have a Vector3Value named “Vel” in the same parent as the script):
local gib = script.Parent
local RunService = game:GetService("RunService")
local canmove = true
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {workspace.Gibs}
RunService.Heartbeat:Connect(function()
if canmove == true then
gib.Position = gib.Position + gib.Vel.Value
gib.Vel.Value = Vector3.new(gib.Vel.Value.X * 0.9,gib.Vel.Value.Y - 0.01,gib.Vel.Value.Z * 0.9)
local raycastResult = workspace:Raycast(gib.Position,(CFrame.new(0,0,0) * CFrame.Angles(-90,0,0)).LookVector * ((gib.Size.Y / 2) + 0.1), raycastParams)
if raycastResult then
print("Bounce")
gib.Position = gib.Position + Vector3.new(0,gib.Vel.Value.Y * -1,0)
print(gib.Vel.Value.Y)
if gib.Vel.Value.Y < -0.1 then
gib.Vel.Value = Vector3.new(gib.Vel.Value.X,gib.Vel.Value.Y * -0.5,gib.Vel.Value.Z)
gib.Orientation = Vector3.new(math.random(-360,360),math.random(-360,360),math.random(-360,360))
else
gib.Vel.Value = Vector3.new(gib.Vel.Value.X,0,gib.Vel.Value.Z)
gib.Orientation = Vector3.new(0,math.random(-360,360),0)
canmove = false
end
end
else
game.Debris:AddItem(gib,5)
script:Destroy()
end
end)