for some reason my splash is way off from were it hit, any help?
local part = script.Parent
local raycastDistance = 100
if not hit.Parent:FindFirstChild("Humanoid") then
local raycastResult = workspace:Raycast(part.Position, (hit.Position - part.Position).Unit * raycastDistance)
if raycastResult then
local hitPart = raycastResult.Instance
local hitCFrame = hitPart.CFrame
local randomnum = math.random(1, 3)
local splashpart = game.ReplicatedStorage.Splash:FindFirstChild("splash"..randomnum):Clone()
splashpart.Parent = workspace
local hitLookVector = hitCFrame.LookVector
local hitUpVector = Vector3.new(0, 1, 0) -- Set the up vector to point upwards
local hitRightVector = hitLookVector:Cross(hitUpVector)
splashpart.CFrame = CFrame.new(raycastResult.Position, raycastResult.Position + raycastResult.Normal)
splashpart.CFrame = splashpart.CFrame * CFrame.Angles(0, math.rad(90), 0)
splashpart.Color = script.Parent.Color
it could possibly be something to do with adding the normal to the raycast result position
I don’t see how this would make it not acurate as I researched quite a few devforum posts on trying to make this and I saw them all add the normal
what does adding the normal do exactly?
Im not exactly sure but I believe it is perpendicular to the surface
remove it and see what happens. from there, you may be able to find a solution
I tried that but it did not work
what changed when you got rid of that bit?
It broke and put it in the normal CFrame of the part that was not moved
you made sure you did:
splashpart.CFrame = CFrame.new(raycastResult.Position)
No this script is like this tio get the position and rotation not just the position
the normal sets the rotation??
I’m not sure what the problem is, but you could try starting the raycast from above the part by a small offset like so:
local raycastResult = workspace:Raycast(part.Position + Vector3.new(0,1,0), (hit.Position - part.Position).Unit * raycastDistance)
Or you could try to, similar to what @Chiseled_Cheese mentioned, set the CFrame of the splash differently:
splashpart.CFrame = CFrame.new(raycastResult.Position) * CFrame.Angles(0, math.rad(90), 0)
I’m not familiar with the normal vectors, so I’m not sure where the RaycastResult.Normal comes into play…
fixed it myself
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.