im making a game where you are a ball and you need to throw off other player from the map, but i have a problem, even when they are almost on full speed, they hit very weak, like its nothing, i wanna make them stronger when they collide. i tried setting custom physical properties but that dosent seem to work/i did it wrong. the current cus.phys.prop. are right now:
Density: 0.7(i dont wanna change this cuz it will make them slower)
Elasticity: 1
ElasticityWeight: 1
Friction: 1
FrictionWeight: 0.4
i tried making hard and long scripts for doing the physics with Vector forces and etc. but that didnt really work.
heres what script i did:
local ball = script.Parent:WaitForChild("Head")
local boostFactor = 2 -- Increase the reflected velocity by 20%
local detectionWindow = 20
local activeChecks = {}
local objectDebounce = {} -- Prevent multiple triggers from the same object
local debounceTime = 0.1
local spawndb = 1
-- Damping factor to reset velocities gradually
local velocityDampening = 0.1
-- Function to handle kill tracking
local function checkIfDied(hit, attacker)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local connection
connection = humanoid.Died:Connect(function()
local currentKills = attacker:GetAttribute("kills") or 0
attacker:SetAttribute("kills", currentKills + 1)
connection:Disconnect()
activeChecks[hit] = nil
end)
task.delay(detectionWindow, function()
if connection.Connected then
connection:Disconnect()
activeChecks[hit] = nil
end
end)
end
end
-- Touched event for the ball
ball.Touched:Connect(function(hit)
-- Проверяем, что объект `hit` имеет родителя и это модель
local parentModel = hit.Parent
if not parentModel or not parentModel:IsA("Model") then
return
end
-- Проверяем, есть ли в модели объект `Humanoid`
local humanoid = parentModel:FindFirstChild("Humanoid")
if not humanoid then
return
end
if not hit:IsA("BasePart") then
return
end
-- Избегаем повторных срабатываний с тем же объектом
if parentModel == ball.Parent or objectDebounce[parentModel] then
return
end
-- Помечаем объект как обработанный
objectDebounce[parentModel] = true
task.delay(debounceTime, function()
objectDebounce[parentModel] = nil
end)
-- Рассчитываем отражение скорости
local normal = (ball.Position - hit.Position).Unit
local currentVelocity = ball.AssemblyLinearVelocity
local reflectedVelocity = currentVelocity - 2 * currentVelocity:Dot(normal) * normal
-- Увеличиваем отраженную скорость
local boostedVelocity = reflectedVelocity * boostFactor
ball.AssemblyLinearVelocity = boostedVelocity
-- Сбрасываем скорость после удара
task.delay(0.1, function()
ball.AssemblyLinearVelocity = ball.AssemblyLinearVelocity * velocityDampening
end)
put more force in the ball, and make it’d Density higher so it behaves the same but has more inertia.
put an ApplyImpulse in the player that’s been hit facing the direction that the hit player should be thrown. It gives an instant force to move an object.
Also try searching the forums for “knock back” or “push back”. I’ve seen a lot of posts about people wanting a punch or hit between players to force one back in an attack.
local normal = (ball.Position - hit.Position).Unit
local currentVelocity = ball.AssemblyLinearVelocity
local reflectedVelocity = currentVelocity - 2 * currentVelocity:Dot(normal) * normal
-- Увеличиваем отраженную скорость
local boostedVelocity = reflectedVelocity * boostFactor
-- Применяем импульс, а не просто заменяем скорость
ball:ApplyImpulse(boostedVelocity * hit:GetMass())
i alr did, and with force “2.6107070417605566e+29, 5.914432320772474e+29, 1.8968249171512295e+28” it still did nothing lol. (i changed the boost factor to crazy numbers, and btw the mass is always 3392)
heres how the script looks rn:
local ball = script.Parent:WaitForChild("Head")
local boostFactor = 9999999999999999999999999
local detectionWindow = 20
local activeChecks = {}
local objectDebounce = {} -- Prevent multiple triggers from the same object
local debounceTime = 0.1
local spawndb = 1
-- Function to handle kill tracking
local function checkIfDied(hit, attacker)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local connection
connection = humanoid.Died:Connect(function()
local currentKills = attacker:GetAttribute("kills") or 0
attacker:SetAttribute("kills", currentKills + 1)
connection:Disconnect()
activeChecks[hit] = nil
end)
task.delay(detectionWindow, function()
if connection.Connected then
connection:Disconnect()
activeChecks[hit] = nil
end
end)
end
end
-- Touched event for the ball
ball.Touched:Connect(function(hit)
local parentModel = hit.Parent
if not parentModel or not parentModel:IsA("Model") then
return
end
local humanoid = parentModel:FindFirstChild("Humanoid")
if not humanoid then
return
end
if not hit:IsA("BasePart") or hit.Parent.Name == "n00b" then
return
end
if parentModel == ball.Parent or objectDebounce[parentModel] then
return
end
objectDebounce[parentModel] = true
task.delay(debounceTime, function()
objectDebounce[parentModel] = nil
end)
-- Рассчитываем отражение скорости
local normal = (ball.Position - hit.Position).Unit
local currentVelocity = ball.AssemblyLinearVelocity
local reflectedVelocity = currentVelocity - 2 * currentVelocity:Dot(normal) * normal
-- Увеличиваем отраженную скорость
local boostedVelocity = reflectedVelocity * boostFactor
local power = boostedVelocity * hit:GetMass()
-- Применяем импульс, а не просто заменяем скорость
ball:ApplyImpulse(power)
print(power)
-- Проверяем смерть и учитываем убийства
if not activeChecks[parentModel] then
activeChecks[parentModel] = true
local attacker = ball
task.spawn(function()
checkIfDied(hit, attacker)
end)
end
end)
upd: so i got why it was doing nothing, cuz i was applying the force on myself not on the target, i fixed it and now i only need to adjust the power and things.
Hehe, sometimes it’s the simplest things.
Make sure you mark the above post as the Solution so other people don’t keep trying to solve it 3 years from now.