I’m working on a torch script which can be placed on walls through mouse. So I’m just asking if I could use raycasting to find walls. Should I cast rays to all directions from the character or is there any other way???
I’m not sure to get what you want to do. If you aim at placing the torch on a wall where the mouse is pointing, you could use Mouse.Target
and/or Mouse.Hit
. If that’s not what you meant, try to be more specific.
It’s that when I click on a wall the torch aces you don’t have to mind about the rotation I’m saying is that to only place torch on walls and not on floors
The most convenient way to do this would be with CollectionService
. Give a specific tag to all your walls and only place the torch if the target part has this tag.
try magnitude idk(extra character)
Can u explain what collection service is?? Can u give me any link
https://developer.roblox.com/en-us/api-reference/class/CollectionService
You could try reading this : CollectionService in a nutshell
If, for example, the player had equipped a torch and wanted to place it, this is what I would do.
I’d raycast from the mouse, towards the position the player clicked on.
Then, I’d get the distance from the player to the wall, and if it’s too large just do nothing. Otherwise place the torch where the player clicked.
It does have some issues which are easily fixable, namely what if the player clicks on the bottom of the wall or top, causing the torch to clip through surrounding geometry.
Is this what you’re looking for?
The best way to detect a wall around a player is ray casting, but this isnt done for building games, as you said your placing a torch, so you need to go with mouse.Target and check like this
if mouse.Target ~= nil then
if mouse.Target.Name == "Wall" then
print("Player mouse is on a wall")
end
end
Exactly. . “Trying to post as it should contain over 30 words”
exampleplace.rbxl (36.9 KB)
This should be it. If you want me to make the part always face the player, just say so. It was pretty fun and it gave me an idea for a game. Tell me if this is the answer, always happy to help.
–EDIT FROM HERE–
Oh yeah I should mention controls, just click on the wall. If you’re close enough (closer than 15 units) the part will move to where you clicked. I can change it from left click to anything else if you want me to.
Thanks mr goldminer this was what I was lookin for