Better methods for trail collision detections

I’ve wanted to make a game like Volt but with roblox’s trails.

What I want to achieve: when you touch the trail of someone else’s bike, it will kill you.
What I tried to do: have lots of parts created behind the bike using Heartbeat but the problem is if your bike’s speed is above 100, they’re not accurate (Image above)

There’s also a performance issue with this, because I want to detect collisions, I’d have to use Touched and it’s expensive.

Any ideas?

1 Like

You could use Raycasting as your hitbox. Raycasting is pretty useful in situations like this, just use a loop or something that runs whenever your players moving and continues to check with rays at each position frame you were at before. You can always end the loops after a certain amount of time, and it doesn’t have to be a loop there’s other workarounds to improve performance.

Also another note to add is that you’re using way too much parts for your detection. Increasing the length of each part, may help solve your issue.

Also another note to add is that you’re using way too much parts for your detection. Increasing the length of each part, may help solve your issue.

Yeah I already did that, but then it won’t get so accurate when I want to rotate my bike in another direction (and not only that but the problem remains, they’re still behind).

You could use Raycasting as your hitbox. Raycasting is pretty useful in situations like this, just use a loop or something that runs whenever your players moving and continues to check with rays at each position frame you were at before. You can always end the loops after a certain amount of time, and it doesn’t have to be a loop there’s other workarounds to improve performance.

I’ve never worked with raycasting however I think it could work but I am not really sure how I can make it detect what’s behind my bike? And it needs to detect curves, not a straight line

The thing about what you want is that as your player curves the ray will curve with it. Here’s an example of how it would look if you did this with raycasting.

local character = script.Parent
local root = character.PrimaryPart

function newRay(Position, LookAt)
	coroutine.wrap(function()
		local params = RaycastParams.new()
		params.RaycastFilter = Enum.RaycastFilterType.Blacklist
		params.FilterDescendantsInstances = {character}
		local cankill = true
		delay(5, function()
			cankill = false
		end)
		local rs
		rs = game:GetService("RunService").Heartbeat:Connect(function() -- don't actually use heartbeat it's deprecated
			local ray = workspace:Raycast(Position, LookAt, params)
			if ray and ray.Instance then
				if ray.Instance.Parent:FindFirstChild("Humanoid") and ray.Instance.Parent ~= character then
					ray.Instance.Parent:BreakJoints()
				end
			end
			if not cankill then
				rs:Disconnect()
			end
		end)
	end)()
end
while wait(.5) do
	local position, lookat = root.Position, -root.CFrame.LookVector * 5
	newRay(position, lookat)
end
1 Like

Solid work however I am not really sure how I would make it detect bigger distances

It’s either you use that method, touched, or the most costy one of all which would be to use Region3. Either way all 3 of them work the way you want I recommend increasing the length of the ray and the lasting time if you want it to detect. Base the length, and lifetime on the trails length and lifetime.

Faster loop and some modifications to detect speed, and lifetime fixed it. Thank you.

local position, lookat = root.Position, -bike.Fund.CFrame.LookVector * math.floor(bike.VehicleSeat.Velocity.Magnitude)/6
2 Likes