Stop skid marks from showing in the air

Hi, I’m trying to work with Roblox’s racing chassis and I made a small script to add tire marks and tire smoke. The tire marks are trails which are enabled when the wheels slip on the ground and disabled when not. There’s one problem though, the tire marks still show up even if you’re mid air. How do I prevent this from happening?

I’ve thought of raycasting but wouldn’t that be laggy? Is there any easier way?

My code:

car.Chassis.TiresSlidingLoopSound:GetPropertyChangedSignal("Volume"):Connect(function()
	
	if car.Chassis.TiresSlidingLoopSound.Volume > .2 then
		for _, v in pairs(car.Wheels:GetDescendants()) do
			if v:IsA("Trail") then
				v.Enabled = true
			end
		end
	else
		for _, v in pairs(car.Wheels:GetDescendants()) do
			if v:IsA("Trail") then
				v.Enabled = false
			end
		end
	end
end)

An example of what happens:


2 Likes

Raycasting would work but just checking if any of the tires are touching another part of terrain would be easier. Use WorldRoot | Documentation - Roblox Creator Hub

To check if the tires are touching. Doing this can cause lag but running a loop that checks like 10 times a second shouldn’t cause any sort of noticeable lag for players. Also just choose one tire and check if that one is touching as from what I believe it’s either all or none of them are touching the ground.

1 Like

All I can find under WorldRoot is “GetTouchingParts” and stuff like that. How would that work with terrain? And wouldn’t it lag because it would have to check each vertex & stuff like that?

I believe that terrain should also be in the table that is returned from get parts in part.

But I’m not sure

You could also just cast a ray down from the player so that it’s just a bit further down then the cars tires and see if it hits anything. I know you suggested that but that would work too

I tried raycasting, it works but not always. It still sometimes shows tire marks in the air.

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {car, game.Players.LocalPlayer.Character}

car.Chassis.TiresSlidingLoopSound:GetPropertyChangedSignal("Volume"):Connect(function()
	
	local result = workspace:Raycast(car.Chassis.Position, Vector3.new(0,-3,0), raycastParams)
	
	if (result) then
		if (result.Instance) then
			if car.Chassis.TiresSlidingLoopSound.Volume > .2 then
				for _, v in pairs(car.Wheels:GetDescendants()) do
					if v:IsA("Trail") then
						v.Enabled = true
					end
				end
			else
				for _, v in pairs(car.Wheels:GetDescendants()) do
					if v:IsA("Trail") then
						v.Enabled = false
					end
				end
			end
		end
	else
		for _, v in pairs(car.Wheels:GetDescendants()) do
			if v:IsA("Trail") then
				v.Enabled = false
			end
		end
	end
end)
1 Like

I don’t understand why your loop runs whenever the volume changes. Could that be the issue?

I’m using Roblox’s racing template’s vehicle which changes the sound volume from 0 to 2.5 of the “TiresSlidingLoopSound” so I’m detecting when the tires skid (when the TiresSlidingLoopSound is above 2)

If the car stops touching the ground without the tires skidding the loop wouldn’t have ran

The raycast seems to work but when the vehicle is mid and and is upside down for example, the marks still appear. I’m unsure if it’s because of the vehicle being upside down but it is.

The tires still make skid noises when the car is mid air. I’m unsure why but that’s how roblox’s car works. I’m not trying to fix the skid sounds, just the skid marks.

That could be because the game decides the tires have skid. Do another raycast before making the skid marks visible whenever the game detects a skid

Do the raycast and check if the car is touching the ground before playing any sounds

Well, I’m not really trying to mess with that because I don’t even know where in the code that is, and I don’t really have a problem with it. All I really need is the trails to not show up mid air.

I don’t know much about Roblox’s default car system as I never used it. I think just checking that the car is touching the ground before anywhere any code is making the skid marks viable should work

I’m busy right now so I can’t test what I’m saying on my computer

1 Like

Well that won’t really change anything, because it’s basically the same thing. I already added the raycast to the tire mark part, which isn’t working when the car is upside down mid air. Just adding that same code to a sound won’t really do anything, and it’d just run the raycast more which causes it to lag more.

1 Like

That’s because the raycast direction you’re using constantly points downwards relative to the world, instead of the car’s cframe. If that even makes sense, but to fix it you can just use chassis.CFrame.UpVector *-3

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {car, game.Players.LocalPlayer.Character}

car.Chassis.TiresSlidingLoopSound:GetPropertyChangedSignal("Volume"):Connect(function()
	
	local result = workspace:Raycast(car.Chassis.Position,car.Chassis.CFrame.UpVector *-3, raycastParams)
	
	if (result) then
		if (result.Instance) then
			if car.Chassis.TiresSlidingLoopSound.Volume > .2 then
				for _, v in pairs(car.Wheels:GetDescendants()) do
					if v:IsA("Trail") then
						v.Enabled = true
					end
				end
			else
				for _, v in pairs(car.Wheels:GetDescendants()) do
					if v:IsA("Trail") then
						v.Enabled = false
					end
				end
			end
		end
	else
		for _, v in pairs(car.Wheels:GetDescendants()) do
			if v:IsA("Trail") then
				v.Enabled = false
			end
		end
	end
end)

And to fix the trail appearing midair sometimes, just move the trail’s attachment to the raycast position.

3 Likes

Thank you so much!

abcdefgjhijk

Now it’s only showing the trail when the car is lifted off the ground. For example when I drive up onto a part, for the second that my car is heading onto the part, it shows the trail, and shows it midair. It didn’t do that before but now it suddenly is???

My code:

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {car, game.Players.LocalPlayer.Character}

car.Chassis.TiresSlidingLoopSound:GetPropertyChangedSignal("Volume"):Connect(function()
	
	local result = workspace:Raycast(car.Chassis.Position,car.Chassis.CFrame.UpVector *-3, raycastParams)
	
	if result then
			if car.Chassis.TiresSlidingLoopSound.Volume > .2 then
				for _, v in pairs(car.Wheels:GetDescendants()) do
					if v:IsA("Trail") then
						v.Enabled = true
					end
				end
			else
				for _, v in pairs(car.Wheels:GetDescendants()) do
					if v:IsA("Trail") then
						v.Enabled = false
					end
				end
			end
		end
end)
1 Like

It’s possible that your trail attachments is probably too low, and ends up making the trail appear inside the ground.

2 Likes

alr i’ll check and let you know tomorrow.

2 Likes