I am having issues with CameraPointToRay as seen in the below gif:
https://gyazo.com/567b793c73c211748f9b481fe7bc5e1d
The ray ignores the character and goes ahead, the only time the ray will hit, is if the crosshair is right on the model or partially on if spread will work out.
I dont know why this is happening, because I have tried multiple things like redrawing the ray, changing the origin (which completely offsets it from the crosshair, not the topbar offset though, some other offset), tried viewporttoscreenpoint.
What i’d assume is that its not taking into account the custom origin and just firing a ray from the middle of the screen to the desired point and i have completely messed up the visualisations.
Nothing will work that I try, thanks for reading, here is some of the code:
part of gun module, getRandomPointInsideCrosshair gets a random position inside a circle based on the crosshairsize
local X : number, Y : number = CrosshairUtils.getRandomPointInsideCrosshair(self.itemData.crosshairSize);
local screenX : number = absolutePosition.X + (crosshairSize * 0.5) + X;
local screenY : number = absolutePosition.Y + (crosshairSize * 0.5) + Y;
local unitRay : Ray = Camera:ScreenPointToRay(screenX, screenY);
local ray : Ray = Ray.new(unitRay.Origin, unitRay.Direction * self.itemData.bulletRange);
local spawnPosition : Vector3 = self.itemRenderer.equipped.PrimaryPart.Muzzle.WorldPosition;
local hitCharacter : Model = Shoot.fireHitscanBullet(Player, spawnPosition, ray.Origin, ray.Direction, self.itemIgnoreList, self.itemData, itemState);
Then the shoot module:
local function fireHitscanBullet(firer : Player, origin : Vector3, rayOrigin : Vector3, rayDirection : Vector3, itemIgnoreList, itemData, itemState)
local ray : Ray = Ray.new(rayOrigin, rayDirection);
local hit : BasePart, position : Vector3, normal : Vector3 = workspace:FindPartOnRayWithIgnoreList(ray, itemIgnoreList.ignore);
end;