H3kken
(minksjesper)
September 13, 2021, 9:29am
#1
I want to create a gun that makes a surface at the position of a raycast hit. The position works, however, I also want to orient the part so it’s equal with the hit’s surface.
This is how the gun works right now.
This is how the part is currently being oriented:
This is how I want the part to be oriented:
This is my code:
I’ve searched the forum but I didn’t really find an answer. Would anyone help?
3 Likes
The raycast normal has the info needed to align with the surface orientation.
vitu0089
(vitu0089)
September 13, 2021, 10:03am
#3
1 Like
TopBagon
(Bagon)
September 13, 2021, 10:49am
#4
Use raycast normal to achieve that and set the cframe of a part instead of a position. Try something like this:
p.CFrame = CFrame.new(Pos, Pos + Normal)
You may have to multiply this by some constant depending on your part
5 Likes
H3kken
(minksjesper)
September 13, 2021, 10:51am
#5
Thanks, I actually found a post about this somewhere, it has the same solution as you.
The third value that FindPartOnRay() returns, is the surface normal of the area that was hit. You can use this to orientate your spray paint part’s orientation to match the orientation of the hit surface.
Some example code:
local hit, pos, normal = game.Workspace:FindPartOnRay(ray) --normal is a vector that points in a certain direction
local SprayPaintPart = game.ServerStorage.SprayPaintPart:Clone()
SprayPaintPart.Parent = workspace
SprayPaintPart.CFrame = CFrame.new(pos, pos + normal) …
1 Like