Hi, so I would like to differentiate between ground terrain and water terrain for my boat placing system but I don’t know how I would do this since both of them are called “Terrain” under mouse.Target.Name. How would I be able to identify water type of terrain in other words. Thanks a lot!
You could probably use Raycasting for this on the Boat, and implementing RaycastParams()
which has a property called “IgnoreWater” & it can be set to true or false
This is probably the only way checking if the Terrain is Ground or Water
The only way to check terrain type is using RayCast
Are you guys sure? All the properties for water and ground terrain are the exact same? Thanks
yes.
local raycastresult = workspace:RayCast(blablabla)
if raycastresult then
print(raycastresult.Material)
end
--> will print the material hit or nil
Okay, i’ve never used raycasting before (well I did once but I forgot), is there an easy way to get the material of terrain from where the mouse is pointing? If it’s not hard enough code, please give me it or I will accept advice. Thanks.
No I don’t believe the mouse will return the material type, RayCasting is the only way.
Okay so I used raycasting but it says that the target’s “Material” property is plastic for both ground terrain and water. Did I do anything wrong? Why is it giving me plastic as material? Thanks again
Yes you did something wrong because I tried it and it works, if you cast a ray towards terrain it will return the terrain material as RayCastResult.Material
Sorry to bother you but could I have the code? For me it keeps saying the material is 256 (plastic I guess) and this is my code for MouseRay:
local mouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
mouseRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 50)
Is 50 too low or something? What am I doing wrong? Thanks
Okay I just realized I sent you a video that uses the deprecated Ray.new
Instead there is the new and improved Raycast there is a demonstration on the API page but basically it looks like this
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {workspace.stuff_not_to_hit}
params.IgnoreWater = false
loal RaycastResult = workspace:Raycast(Mouse.UnitRay.Origin, Mouse.UnitRay.Direction * 1000, params)
if RaycastResult then
local hit = RaycastResult.Instance
local position = RaycastResult.Position
local normal = RaycastResult.Normal
local Material = RaycastResult.Material --> this will return the terrain material
end
all this is on the API page
Thank you for giving me the whole code and solving this mess for me. Hopefully as I see this as an important subject on scripting, other people will now know what to do because of you and the others that tried to help. Thanks so much you saved me!