Projectiles // RayCasting issues

I’m having an issue with my RayCasting Projectiles -
It seems that depending on the Speed of the Projectile - It passes straight through objects without detecting them.

The wall you see in the video provided is loaded ClientSide - This is because I need my System to recognise when it’s hit a ‘Local’ Part (( For asthetic reasons && to prevent it travelling through ‘Local’ Parts. )) as the Projectiles generation and movement is handled by the Server.

The first few rounds are with the Speed set to 1. The others following are between 8 - 16 - Roughly where I need it to be.

ServerScript:

			for i = 1, math.huge do
				if not Laser or i == 100 then break end
				wait()
				local raycastResult = workspace:Raycast(Laser.Position, Laser.CFrame.LookVector * Speed, raycastParams)
				if not raycastResult then
					SpeedInc.Value, CFrameInc.Value = Speed, Laser.CFrame
					Laser.CFrame = Laser.CFrame + Laser.CFrame.LookVector * Speed
				else
					Laser:Destroy()
					Create_HitPart(LaserID, raycastResult.Position, nil)
					break
				end
			end

LocalScript:

Character.ChildAdded:Connect(function(Child)
	if Child.Name == "Laser" then
		local LaserID = Child:WaitForChild("LaserID").Value
		
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {Player.Character}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		local raycastResult = workspace:Raycast(Child.CFrame.p, Child.CFrame.LookVector * Child:WaitForChild("SpeedInc").Value, raycastParams)
		if raycastResult then
			print("Yes")
		end
		
		Child:WaitForChild("CFrameInc").Changed:Connect(function()
			raycastResult = workspace:Raycast(Child.CFrame.p, Child.CFrame.LookVector * Child:WaitForChild("SpeedInc").Value, raycastParams)
			if not raycastResult then
			else
				Child:Destroy() print("Hit")
				FireServer(RemoteEvent, "onHit", nil, {LaserID = LaserID, HitPos = raycastResult.Position, Laser = Child})
			end
		end)
	end
end)

1 Like

Interesting way your trying to capture an event for your ray.

So for 1, change it from cframe changed to stepped.

That will be the fastest update you can use.

Understand that what your seeing is that the update on cframe is not fast enough and basically the part is passing through between the scan that should check it.

There are other. Things that get more complex on how to handle this but thats your problem atm.

Keep the ray short, and the fast calls shouldn’t cause to much drain.

1 Like

Hey! I would recommend using FastCast. It handles all of this for you in a much simpler way.

1 Like

Hi, I’ve trialled this and had no success.

@recanman - I’m not familiar with FastCast nor whether I can use it ClientSided to detect Local Parts.

iiKossmoZ DM me your discord, so i can get faster review of whats going on. I know raycast can be weird at times it took me a bit to get a wrangle on robloxes, But yea I can also explain some more complicated implimentations you can that May work out better for you. Depending on what you want to do.