#Impact effects(emitter) on objects and parts (hit location)
1 messages · Page 1 of 1 (latest)
https://create.roblox.com/docs/workspace/raycasting
you pass an origin and a direction, the magnitude of the check is dictated by the direction so if you wanted to use the camera's lookvector like in the example, you could do
local scan_dist = 5
local results = workspace:Raycast( workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector * scan_dist )
You can mess w RaycastParams in order to set ignore parts or whitelisted parts https://create.roblox.com/docs/reference/engine/datatypes/RaycastParams
How would i use those lines ? I have no clue how to script any of it lol...
Its first person view btw
I seriously have no clue how i would code that
If you're using the tool object as your item, you can connect a function to the Activated event and do the raycast for hit detection when it is activated
But how does the tool know
or how do i make it hit something
like, uhm. fuck
I dont know how to explain im too autistic for that
can you code it for me :3
local scan_dist = 5
local raycastResult = workspace:Raycast( workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector * scan_dist )
if raycastResult then
print(raycastResult)
end
it prints the Distance, Instance, Material, Position, and the Normal
you gotta try it yourself, if you need help setting up a connection that's kind of a separate issue lol
I'm not a good scripter... rather a newbie
This isn't the place to have work done for you tho. You will not learn if you don't try
Obviously you're interested because you're doing something on studio
So give it your best shot and if it completely fails, lmk
here's how you can do a basic connection:
workspace.BasePlate.Changed:Connect( function()
-- code
end )
or you can declare the function before connecting it, which lets you call it in different contexts besides just the connection:
local function basePlateChanged()
-- code
end
workspace.BasePlate.Changed:Connect( basePlateChanged )
I fail everytime cus i got no fucking clue what im doing
there's no point because i dont learn shit if others dont teach me it
and just words dont help
"Yeah if you put that and that connect it to function and string and"
Yeah but how the fuck do i actually programm it
Just ask
in your case, say you put a localscript in the tool, you could set the tool as a variable by referencing where it is relative to the script;
-- in a script that is parented to a tool
local tool = script.Parent -- .Parent always goes up to the next parent
tool.Activated:Connect(function()
-- here you can run a raycasting operation
end)
read and learn
just saying... i dont know shit about raycast....
I know a bunch of basics but i got quick limits man
Well I already explained how to go about raycasting and how to visualize it
sucks to suck
You need to take things one step at a time
You don't know how to do connections so learning the basics of raycasting doesn't really serve you much
exactly
I mean im autistic i do learn quickly but sometimes i need so much explaination it drives poeple insane
All you gotta do is ask or @ reply the helpers, but don't ask us to do it for you because you're just doing yourself a disservice
Once you got some use case examples down I think you'll do fine
Try making the script print when you activate using the print function, once you got that, try printing the workspace camera's position and it's lookvector
and then once you can see in output that you're getting info you expect, you can set it to variables and use it in the raycast like we talked about earlier. If you don't know anything about setting up functions and local variables and whatnot then you should watch some basic functionality tutorials, 5 min youtube search and here is a decent one https://www.youtube.com/watch?v=l8yVbGsiL4o
This tutorial will teach you how to use functions in Roblox Studio scripting, including parameters and arguments. This topic is crucial to understand Events which are coming next!
Join membership for EXCLUSIVE perks:
https://www.youtube.com/channel/UCp1R0TBvgM7gj0rwTYULmSA/join
SUBSCRIBE to learn how to master Roblox scripting:
https://www.you...
local tool = script.Parent doesnt seem to work and script.parent.parent seems to provoke activated
it says its not a valid member im like so confused right now
Now its spamming a bunch of other errors aswell that i never wanted
this might help understanding raycasts
-- in a script that is parented to a tool
local tool = script.Parent -- .Parent always goes up to the next parent
tool.Activated:Connect(function()
-- here you can run a raycasting operation
local scan_dist = 5 -- distance in units of how far the raycast casts
local raycastResult = workspace:Raycast(workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector * scan_dist ) --workspace:Raycast( the Camera's Position, the CurrentCamera's LookVector * scan_dist)
if raycastResult then
print(raycastResult.Instance.name) --prints the hit object's name
print(raycastResult) -- prints the Distance, Instance, Material, Position, and the Normal
if raycastResult.Material == Enum.Material.Instance.Metal then -- if the part you hit is metal, it prints smth
print("Metal Hit Sound")
end
end
end)
Jesus christ
sorry
where is the script?
its legit
Wrench = script.parent
and it doesnt work lol
oh
im retarded
I put the script inside the handle not the tool itself
HRGRHUGAUJHGAEGAEGAJGEAJGEJGRJHGJHHFKNHKHKHDKHTKHTKTKKTHTHKTHH
average coding moment
Is it even localscript or normal one
its a localscript