Help with raycasting direction relative to where the character is facing

I’m not very good at math, so I am trying to make the direction my blood is squirting relative to the direction the character is facing. Right now it can only go one direction which is this:
(It’s spewing out of a attachment)

Here is the part of the script:

	local rayDirection = Vector3.new(math.random(-200,200), -workspace.Gravity, -math.random(200,400))
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {character, workspace.Blood}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)```
1 Like

Use the character’s HumanoidRootPart to get the orientation of the player.

Elaborate on that please? I mean how would I get the direction of the raycast to affect the way blood spurts out?

For now, I would just experiment with some of the values in the rayDirection and see which ones work for the character. I’ve not used raycasts in a while so I can’t really help that much.

Where is rayOrigin variable declared and initialized?

I’m on mobile and formatting is hard for me sorry

Here’s the full part:

local rayOrigin = script.Parent.WorldPosition
	local rayDirection = Vector3.new(math.random(-200,200), -workspace.Gravity, -math.random(200,400))
	if Torso.Orientation.Y > -60 and Torso.Orientation.Y < -120 then
		rayDirection = Vector3.new(math.random(-200,200), -workspace.Gravity, -math.random(200,400))
	elseif Torso.Orientation.Y < -60 and Torso.Orientation.Y > -120 then
		rayDirection = Vector3.new(-math.random(200,400), -workspace.Gravity, math.random(-200,200))
	end

I think you could use -HumanoidRootPart.CFrame.RightVector*math.random(200,400)-Vector3.new(0,workspace.Gravity,0)+HumanoidRootPart.CFrame.LookVector*math.random(-200,200) as the ray direction

2 Likes

Thanks, solved my problem and its more aligned with the character

1 Like

Instead of using torso, I would recommend using the HumanoidRootPart as that is the pirnary part of any character and EVERY charactee has one. Also using the humanoid root part’s front face can be used to determine the front of a character.

you can use

HumanoidRootPart.CFrame.LookVector to get the front side of the HRP

So like spawn the blood for example 5 studs from the HRP front face, which is the same as the front of the player’s character.

Is that what you are intending to do?

1 Like

Nube beat me to it!! lol he explained it better though

2 Likes