i was looking for this system and ended up finding this thread
i modded his code into my version
local function Collide(part, hitPart)
if hitPart and hitPart.CanCollide then
if not (hitPart:IsDescendantOf(car) or hitPart:IsDescendantOf(workspace.PowerupDebris)) and math.abs(hitPart.Position.Y - part.Position.Y) < 1 then
local carModel = GetEntireModel(hitPart)
if carModel and carModel:FindFirstChild("DriveSeat") then
if (tick() - carCollisionDebounce) > 0.1 then
carCollisionDebounce = tick()
if car.Chassis.Velocity.magnitude > stats.CollisionVelocity.Car.Min.Value then
-- Find the position, normal and surface of the hit to pass back for some kind of impact on that part etc
local _, pos, normal = workspace:FindPartOnRayWithWhitelist(
Ray.new(part.Position, (hitPart.Position - part.Position).unit * (hitPart.Position - part.Position).magnitude),
{hitPart}
)
car.DriveSeat.Collide:Play()
print("Collided")
elseif car.Chassis.Velocity.magnitude > stats.CollisionVelocity.Car.Max.Value then
-- Find the position, normal and surface of the hit to pass back for some kind of impact on that part etc
local _, pos, normal = workspace:FindPartOnRayWithWhitelist(
Ray.new(part.Position, (hitPart.Position - part.Position).unit * (hitPart.Position - part.Position).magnitude),
{hitPart}
)
car.DriveSeat.Crash:Play()
print("Crashed")
end
end
else
if (tick() - collisionDebounce) > 1 then
collisionDebounce = tick()
if car.Chassis.Velocity.magnitude > stats.CollisionVelocity.Normal.Min.Value then
-- Find the position, normal and surface of the hit to pass back for some kind of impact on that part etc
local _, pos, normal = workspace:FindPartOnRayWithWhitelist(
Ray.new(part.Position, (hitPart.Position - part.Position).unit * (hitPart.Position - part.Position).magnitude),
{hitPart}
)
car.DriveSeat.Collide:Play()
print("Collided")
elseif car.Chassis.Velocity.magnitude > stats.CollisionVelocity.Normal.Max.Value then
-- Find the position, normal and surface of the hit to pass back for some kind of impact on that part etc
local _, pos, normal = workspace:FindPartOnRayWithWhitelist(
Ray.new(part.Position, (hitPart.Position - part.Position).unit * (hitPart.Position - part.Position).magnitude),
{hitPart}
)
car.DriveSeat.Crash:Play()
print("Crashed")
end
end
end
end
end
end
my expectation is that system should be determining if any car’s part collides with another part on the horizontal side. But in reality, the system doesn’t do very well so here are the flaws:
- this line
math.abs(hitPart.Position.Y - part.Position.Y) < 1
is not really helpful for horizontal touch, but when it is deleted from the function the system works well but still have to be forced to touch in the vertical side - the criteria for velocity only triggers when the car’s velocity meets minimum requirement but not both requirements (minimum and maximum)
so how should i deal with this?