Raycast not going directly under player

You can write your topic however you want, but you need to answer these questions:

  1. I want to spawn an aura at the ground directly under the player

  2. Aura does not spawn where I want it to. It will spawn under the player, but the aura is not centered.

  3. I tried raycasting from lowertorso and humanoidrootpart but that never fixed anything.

My Code:

local Character = script.Parent
	local HumanoidRootPart = Character.PrimaryPart
	
	HumanoidRootPart.Anchored = true
	
	local Params = RaycastParams.new()
	Params.FilterDescendantsInstances = {Character}
	
	local AuraRaycast = workspace:Raycast(HumanoidRootPart.Position, HumanoidRootPart.Position - Vector3.new(0, 50, 0), Params)
	
	if AuraRaycast then
		local Position = AuraRaycast.Position
		
		local Aura = script.Aura:Clone()
		Aura.Parent = Character
		Aura.Position = Position
		Aura.Position = Aura.Position + Vector3.new(0, Aura.Size.Y/2, 0)
		Aura.Anchored = true
		Aura.CanCollide = false
		
	end
1 Like

The second parameter of workspace:Raycast() takes in a vector direction, not a position
so you could just do this

local AuraRaycast = workspace:Raycast(HumanoidRootPart.Position, -Vector3.yAxis * 50, Params)
	
5 Likes

Thank you! That is one thing I did not know about raycasting, so I learned something new as well as fixing my script.