Ik,I did but it is not working.I was checking it out in smaller scale like if it works it would print but nothing happens thats why I was asking if there is something I could fix
Could you make a simple test place and post it? I’d be happy to help you figure it out.
…your part’s position wouldn’t happen to be 9 studs above the surface of the baseplate, would it?
That would be the conditions required to print absolutely nothing in the output log.
local objecthit, hitposition,normal,material = workspace:FindPartOnRayWithWhitelist(YourRayHere, {workspace.Terrain}, false, false)
local hitwater = false
if objecthit.Name == "Terrain" and material == Enum.Material.Water then
hitwater = true
end
--if hitvalue is false, cancel out velocity in that corners direction. Otherwise, do nothing.
I believe this might work better.
I even tried 100 but still it does not work
How are you constructing your rays?
https://gyazo.com/39462187ab898a908eb39d99142c658e --Script
Also UnCopylocked Place : RaftProblem - Roblox
I tested the place. First things first, the code is in a local script so it doesn’t run. You need to place it in a server script if you want it to run server-side.
Also I’ve found out the issue. The problem is that the position of the raft is already in the water, so it ignores the water and the next thing the ray picks up is the grass underneath. Rays have this weird thing where if the starting position is within a part, it ignores that part. To fix this is simple, set the starting position of the ray to be a little bit higher than the raft position. I changed the first line to this and it worked:
YourRayHere = Ray.new(workspace.Raft.Position + Vector3.new(0, 10, 0), Vector3.new(0,-10,0)*100)
You might also wanna have a ray being cast from a position in the front and one in the back so that if you accidently hit land you’re still able to go back.
So I edited the script and it is working fine but the problem is that now how can I repeat the script efficiently every time the raft moves to check the raft is not on Land
–script
YourRayHere = Ray.new(workspace.Raft.Model.Position + Vector3.new(0, 10, 0), Vector3.new(0,-10,0)*100)
YourRaftHere = script.Parent
local objecthit, hitposition = workspace:FindPartOnRay(YourRayHere, YourRaftHere, false, false)
if objecthit.Name == "Terrain" or objecthit.ClassName == "Part" then
if (YourRayHere.Origin - hitposition).magnitude < 10 then – checking if the terrain is close enough to the raft’s hull
print("Working")–stop raft
end
end
You can put it in a while loop and check like every 0.5 seconds, like this:
while wait(0.5) do
-- Put all the code here
end
I will try it
Bad idea. I would use a RunService.Stepped loop if done on the server, or a RunService.Heartbeat loop on the client. This is not an expensive call, one ray a frame is nothing. If you have some sort of event that fires when the ship moves, use that though.
How is it a bad idea? I’ve done checks like this countless of times and I never had to do it every frame. The ship doesn’t move fast enough that you need to check every frame. If anything, the wait delay could be dropped lower to like 0.1 if you want more precision, but definitely not every frame.
You can do around 60,000 raycast calls without any performance issues. There’s no reason to do it in a fixed amount of time as slow as 0.5 seconds, There can be visible time delays which makes it look horrible. Why would you not do it every frame?
Well there’s really no reason to do it every frame because the boat doesn’t move at lightning speed. Thats why I said, you could drop it down to 0.1 seconds or just use wait() which will wait around 0.03 seconds. Thats enough to not see any visible difference at all. Running the code even faster only takes up extra performance with practically no improvement.
That’s every single frame, precisely what I am saying to use.
I stated why to do this
Thats only if the player is running at 30 FPS (which is honestly quite low). And yes I realize what you’re saying about the delay issue but I don’t think it will be visible if ran every 0.1 seconds. I agree 0.5 seconds may be a bit too slow, but I don’t think it should be any lower than 0.1
Either way, its up to @IllustriousEntity how often to run the loop.
Doesn’t matter. Please remain on-topic. These optimisation practices can be discussed with OP privately or you can raise a discussion about this by creating a new thread, not hijacking a thread about detecting terrain from a raycast.
I just don’t understand your reasoning for being lower than wait()… As I said, there’s little to no drawbacks with a huge plus, instant feedback.