Help with Raycasting

So, I am making a dashing script and I need to check the things in front of the player so that he doesn’t dash into them. I am shooting 3 rays straight in front of the player from the player’s LeftLeg, RightLeg and HumanoidRootPart and the problem is the legs move so the 2 rays shoot directly to the ground instead of them shooting always straight. How do I make them shoot always straight no matter how the legs are rotated?

	local raycastParams = RaycastParams.new()
				raycastParams.FilterDescendantsInstances = {char, game.Workspace.ZoneMarkers, game.Workspace.PowerOrbsSpawns, game.Workspace.SafeZones}
				raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
				
			
				local result_Root = workspace:Raycast(root.Position, root.CFrame.LookVector * Vector3.new(Dash_Range, Dash_Range, Dash_Range), raycastParams)	
				local result_LeftLeg = workspace:Raycast(LeftLeg.Position,	LeftLeg.CFrame * CFrame.Angles(math.rad(0),math.rad(0), math.rad(0)).LookVector * Vector3.new(Dash_Range, Dash_Range, Dash_Range), raycastParams)	
				local result_RightLeg = workspace:Raycast(RightLeg.Position, RightLeg.CFrame * CFrame.Angles(math.rad(0),math.rad(0), math.rad(0)).LookVector * Vector3.new(Dash_Range, Dash_Range, Dash_Range), raycastParams)	
				

Try making the direction the humanoidrootparts lookvector, while the position is the legs position

Also you dont have to do * Vector3.new(Dash_Range, Dash_Range, Dash_Range)
You can just do * Dash_Range, roblox will handle the distribution for you

1 Like

Ah ok, Thank you for the help!

1 Like