Does anyone know how to make cars wheel enable dirt when car detects terrain like ground,grass, dirt?
You can use a .Touched
and .TouchEnded
events to detect if something is touching or not and enable/disable the particle emitters and to detect if the tire or parent part of the script is touching terrain you can use :IsA("Terrain")
and to only make the particle active when the car is moving you can check using Velocity.Magnitude
and you can use a RunService Heartbeat to continuously check the Velocity and if the Emitter is enabled or not.
EDIT: changed code to detect if the parent is moving or not
something like this should work, just parent the script and particle emitter to the car wheels.
script.Parent.Touched:Connect(function(dirt)
if dirt:IsA("Terrain") and script.Parent.Velocity.Magnitude > 1 then
script.Parent.ParticleEmitter.Enabled = true
end
end)
script.Parent.TouchEnded:Connect(function(dirt)
if dirt:IsA("Terrain") then
script.Parent.ParticleEmitter.Enabled = false
end
end)
game:GetService("RunService").Heartbeat:Connect(function()
if script.Parent.ParticleEmitter.Enabled and not (script.Parent.Velocity.Magnitude > 1) then
script.Parent.ParticleEmitter.Enabled = false
end
end)
A reliable method would be to utilize raycasting. You could shoot a single ray beneath the vehicle every x seconds to sample the material beneath the vehicle. You could do this for every wheel, but then it’s several raycasts vs just 1, which could have an impact on performance if you plan on having lots of vehicles active at once. It’s really down to how accurate you’d like it to be and how you’d tradeoff performance for this.
Personally, for such a simple effect, I’d use just 1 raycast and shoot it every ~0.6 seconds, which should look very convincing and would run fast and without any problems.
If you want to maximize performance, I’d suggest handling this on the client, and check to make sure the vehicle is within reasonable distance to the camera before updating the effect.
If you have any concerns or need help with any part of the actual scripting, feel free to ask, since this is a lot of information I just threw at you
I wouldnt use a .Touched event for vehicles, unless they move really slowly, .Touched is going to be unreliable, A method like this would work, but probably swap it out for raycasts
ah yea true raycast would be better but can be complicated, I was just trying to provide a simple understandable solution I am still learning lots of things
Thats totally ok! I hope I didnt come off as if I were telling you your method is wrong, I just wanted to inform you so you would have the knowledge going forwards! Mb