Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to get the direction of the bottom surface?

So, I'm trying to make a raycast punch script, and I got stuck on the directioning part of the ray.

What I've Tried

  • -CFrame.UpVector
  • CFrame.LookVector - CFrame.UpVector

Here is the RayCast Script

local punch = game:GetService("ReplicatedStorage"):WaitForChild("Punch")
local rightPunch = game:GetService("ReplicatedStorage"):WaitForChild("RightPunch")

punch.OnServerEvent:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	if character:FindFirstChild("Humanoid") then		
		local humanoid = character:FindFirstChild("Humanoid")
		local newPunch = humanoid:LoadAnimation(rightPunch)
		newPunch:Play()
		
		wait(0.1)
		
		local newRay = Ray.new(character:WaitForChild("Right Arm").Position,(Vector3.FromNormalId(Enum.NormalId.Bottom) * 10))
		local ignoreList = {character}
		local hit, position = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(newRay,ignoreList)
		
		if hit then
			print(hit.Name)
		end
	end
end)

What I'm Trying To Achieve

  • RayCast starts from the Right Arm and goes forward, so I can detect who they have hit.

1 answer

✓ Accepted answer

well i think Vector3.FromNormalId ( ) might be useful;

source

7 comments

0

So, how would I format it? (Look In Script Above)

0

the script looks good, i think you just need to multiply the result for FromNormalId by distance...

0

b/c it only returns a direction vector

0

Alright, ty.

0

It's kinda not working?

0

I'm punching it towards a dummy with a humanoid, and nothing is appearing.

0

hmm

This discussion is preserved as it was. New answers, comments, and votes are closed.