Raycasting going through solid objects

By the way, distance should be (endpoint-origin).Magnitude, apply it on the method @CreepingGamingTV showed you and it should work (atleast, on this case to make it work like that)

Nope, still not working, I also verified that the positions are right by creating a part at the endpoint, so wrong positions wouldnā€™t be the case.

Can you show how it looks like now?

1 Like

Also post your current code so we can see if you made the correct changes

Alright, hereā€™s the new code.

func.Raycast = function(origin,endpoint,ignoreList,range)
	local destination = (endpoint-origin).unit * range
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.FilterDescendantsInstances = ignoreList
	params.IgnoreWater = true
	local part = Instance.new("Part",game.Workspace)
	part.Anchored = true
	part.Size = Vector3.new(1,1,1)
	part.Position = endpoint
	local cast = workspace:Raycast(origin,destination,params)
	return cast
end

Can you check if you given correct values to the function, had a similar problem to this being human error

EDIT:

Maybe check the order in which you gave the values etc

Yes, I am currently looking at my code. I believe I may be adding the wrong value somewhere.

Well could you show how you got the range? Maybe its because of that.

just make a if statement for if the ammo/bullet hits an anchored object then it stops

nothing is hit returns nil, impossible to check if a nil value is anchored or not

Alright, a few days later I decided to use FindPartOnRayWithIgnoreList as it works for me. I am aware it is depreciated, but I am going to use it as a placeholder for now.

1 Like

Were you able to find a concrete solution to this issue? I am having similar issues where my raycasts go through my targets at seemingly random timesā€¦

Edit: Sorry for the necrobump :sweat_smile: