Raycasting being way off when using collision groups

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

  1. What do you want to achieve? Keep it simple and clear!
    Currently my door has detection parts to detect when the player hovers their mouse, but it gets in the way of my raycast, so I resorted to collision groups. I want it to smoothly ignore the detection parts without any problems.

  2. What is the issue? Include screenshots / videos if possible!
    For some reason, my raycast almost ‘reflects’ away from where im shooting at and is way off from where my mouse is, this only happens when im shooting through the collision group parts.

video:

code:

collision group settings:
image

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I just can’t figure out what’s going wrong, I tried messing around with collision groups and with no success, I tried searching up my problem but couldn’t find anything that worked.

your “exactpos” variable is actually the vector not a position

if i understand correctly your main issue is the bullets not going near the right place
i reckon the problem is somwhere in the spread you are trying to apply to the vector and for good measure try without the *config.maxrange

overall just try it with

local Direction = ((exactPos).Unit)*20

see if this makes it better then we will know if we gotta rework the spread and maxrange

I tried what you did, and unfortunately it did not work, the same problem is still happening and it did not seem to change anything. If you need more of the code to be provided please let me know.

Even if the raycast doesn’t hit the ignore parts. The mouse hit position raycasting system will hit as I see you use mouse.hit.p.

I suggest using a custom mouse raycasting system where you can also use raycast params like this function below:

1 Like

Thank you so much!

I never realized that mouse.hit.p was returning the detection parts position and thus messing with the raycast, you don’t know how grateful I am for your help!

1 Like
local viewportMouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)

You are aware that mouse.UnitRay exists right?

https://developer.roblox.com/en-us/api-reference/property/Mouse/UnitRay

Never mind, I see you’re using the UserInputService mouse and not the legacy mouse object.

I got the function from Aerogame framework mouse module.

1 Like