#I'm having issues with Raycasting
1 messages · Page 1 of 1 (latest)
local gun = script.Parent.Parent
local GetMousePosition = game.ReplicatedStorage.GetMousePosition
gun.Activated:Connect(function()
local player = game.Players:FindFirstChild(gun.Parent.Name)
local RayOrigin = gun.Handle.RayOrigin.Position
local MousePosition = GetMousePosition:InvokeClient(player)
local DirectionToFire = (MousePosition - RayOrigin).Unit * 500
local raycastResult = workspace:Raycast(RayOrigin, DirectionToFire)
if raycastResult then
print(raycastResult.Instance)
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getMouseRemote = ReplicatedStorage.GetMousePosition
ReplicatedStorage.GetMousePosition.OnClientInvoke = function()
return game.Players.LocalPlayer:GetMouse().Hit.Position
end
the first one is for the gun and the second is a local script that get the mouse position
** You are now Level 3! **
My issue is that I think the raycastorigin is still on the ground and not sticking to the gun
even tho it is parent to the handle
I think you can add more accuracy for your ray
how ?
sorry for taking ages to reply have been bussy
like the multiplying thing ?
The direction to fire
Maybe if you add a lil bit of accuracy it might work better
I have a gun script I’ll give you a line or two later
Okay okay
Thanks
@sullen mortar
?
How do I make the accuracy better 😅
Gonna give the code later
Theres a line i don’t remember
Ill check when ill be using my pc in 15 minutes
okay, thanks a lot
Yo! Idk if it more accurate but i think a client replication would be better
Whats the main issue tho? The bullet is going to the wrong direction?
Oh forget about it
Maybe, but also what about the way the attachment is on tha handle, i added it in the workspace, but when i click it in the game it shows it as the place in the workspace, not the tip of the gun, i think thats the issue
I read everything now
But im not certain
Can send a video of it?
** You are now Level 1! **
My phone boutta be dead in some minutes. As soon as i get home ill try to help u asap
Oh send it then real quick
First, check if the attachment0 is set to the handle and the attachment1 to the other part u desire to attach
@shy lion
It’s because you are the Position property of the attachment instead of the WorldPosition property
Sorry for the double ping, wasn’t very smart of me
wait what
I've never used that
like
i put the tool in the workspace, I added a Ray origin to the handle and then moved it to the Starter pack
Can u show the attachment properties?
There’s difference between Attachement.Position and Attachement.WorldCFrame.Position
OHHHH
It worked?
Yo
Im gonna give u the line
I made the system a few months ago
The Tool.Activated Event is in the client side script
local function onActivated()
local ray = Camera:ScreenPointToRay(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2 - GuiService:GetGuiInset().Y)
if ray then
local InvokeSuccess, errormessage = pcall(function() SendRayToServer:InvokeServer(ray) end)
if not InvokeSuccess then warn("Invoke error: "..errormessage) end
end
end
Might give a more accuracy
@shy lion
okay thankyou