Gun not shooting straight on mobile

  1. What do you want to achieve? Hello, i am currently working on a gun system and i want to make it mobile compatible.

  2. What is the issue? The gun dosen’t shoot straight it shoots at the shoot button as you can see on this picture :
    image

This is my caster (i use FastCast)
image

  1. What solutions have you tried so far? I looked on forums and tried to fix it myself.

If you need more informations, feel free to ask me

You should cast from the camera position, not the head. If the player has a weird animation, it shows.

Thanks for the information but it’s not really my issue

What is mouseposition? And since you’re using an external API, you may want to check that it’s not the problem. Try casting yourself, and see if anything changes, and also you should probably try what I said previously, because if your game isn’t in r6, I’m 80% sure that’s the problem.

Mouse position is this (from the local script that transfer to the script via a remote event)
image

And i know it’s not the API since it does it with normal raycast i already tried it, and my game isn’t in R6

And how would i get the camera position from the server?

Okay, if your game isn’t in r6, then you should cast from the camera. just try it.

I know, but the issue is that i don’t know how to cast from the camera on the server

then you’ll need to either send the camera position on the client, calculate it from the humanoid root part, or just cast on the client.

This is the problem, the mouse goes to the shoot button because the mouse goes there after the player presses on it.

I know that, i am just trying to find out how i can make the gun shoot straight

your mouse click thing is on the shoot button though (because they are touching the shoot button), try setting mouseposition to a raycast result coming directly from the camera

what animation does your roblox avatar have?

How would i do that, i know it might be a potential solution but i don’t know how to do it

my avatar use the toy animation package

send us a video of you shooting

function RaycastToCameraCenter()
   local rayInfo = RaycastParams.new()
   rayInfo.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
   local result = workspace:Raycast(workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector*1000, rayInfo)
   return result
end

this returns a raycast result object

(we shouldn’t need a video of you shooting btw)

edit: if you wanna do what Den suggests, just set origin to the current camera cframe and the direction to the current camera lookvector, it’ll work exactly the same but cast from the center of the screen instead of your head

1 Like

Yes a video of me shooting is useless

So i put this code in my localscript ?