downcast from root part if raycastmaterial is water then put it back on land
I’m not sure how I would script that it seems complicated.
The simplest way of doing this is to just detect when some part belonging to the car is touching water, if it is then you all you need to do is simply regenerate the car.
local car = workspace.Car
local carPart = workspace.CarModel.CarPart
local water = workspace.Water
carPart.Touched:Connect(function(hit)
if hit.Name == "Water" then --name of part the car hit is water
--regen the car
end
end)
Here’s the logic.
I’m actually using Roblox’s Terrain for this.
I’m not really sure if there’s a way, but you could try adding a part on top of the water. Then you can detect when a part touches the water part. If the other part was a part’s car then put the car back to land.
Great idea! I’ll try that right now.
It didn’t help. It just going to run, but nothing happens when it runs.
From a gameplay design perspective and a programming perspective, it would just be a lot easier to have a gui that will spawn the car like in most “open world” Roblox games.
Better for the user as well as they have more control where the car respawns.
I agree, I think this will be more easier and I might be able to find a tutorial.
Maybe add a PrimaryPart inside the car and set the pivot back to the land?
Something like this?
local carSpawningArea = workspace.carSpawningArea -- Assuming there's a part in the workspace where the cars will spawn back in.
script.Parent.Touched:Connect(function(otherPart) -- Assuming script.Parent is the part on top of water.
if otherPart.Name == "CarPrimaryPart" then
local Car = otherPart.Parent -- Assuming otherPart.Parent is the car model.
Car:PivotTo(carSpawningArea.CFrame)
end
end)
Not 100% sure if it’ll will work but you can give it a try.
(Assumed everything in the script)
How about make some transparent Part walls around the water and use Collision Filtering | Roblox Creator Documentation to just keep the car out of the water?
Instead of Raycasting continually what I would do is to raycast around the car from above if it hits the water.
To be honest a much easier solution would be to make the car heavy and able to drive underwater or make the water height very thin.
That will take to long the water is formed in a huge circle and there’s land between it.
Is it a smooth edged island or does it have lots of rough coastline? A “circle of water with land between it” is a strange description.
The transparent Parts don’t have to exactly follow the edge, just enough to keep the cars out of the water.
If you have a slight indent in the shoreline the cars will probably be able to get back out of the water if the water doesn’t get deep too quick.
Same with small points of land that stick out into the water, you could just keep the cars off that part as well.
Post a picture of your coastline from a decent distance away with a car or a Robloxian next to it so we can see what you are dealing with.
If you can see the small canyon is where the water is at. I removed it so I can work below the water.
Its possible to make a ‘car flip’ script that will move the car x studs in x direction. I’m not sure how you’d detect the best direction to not drop the car right back into the water. You could have it choose a random direction and maybe they get lucky?
I think the best bet would be a gui car spawner for the player based on where they are standing.
In my game, I just left it up to the player to learn that they can’t drive in water.
I thought about making it like a James Bond car where can convert to amphip and cruise around like a boat, maybe some day i’ll make that!
I also I thought of the transformation idea but it works requires a lot.
So it’s a bit tough to tell exactly where your shoreline is in the image you provided, but I have roughly 39 Parts in black that could be used to block a vehicle from going in the water.
Doesn’t seem to be that much work. No scripting involved with Collision Filtering. Players can move through the wall, but vehicles can’t.
You don’t have to have the wall Parts match the shore exactly as long as you are keeping the cars out of the water enough that they don’t get stuck.
Ok, I think this should help with it, since I don’t have to worry about scripting.