-
What do you want to achieve? Hello, i am currently working on a gun system but i encountered an issue.
-
What is the issue? The bullet aim good only at a certain direction, when you are not too far and not too close. As you can see on this picture, crosshair and the bullet hole.
The issue is maybe because the raycast come from the player humanoidrootpart position and goes to the player camera LookVector, i do that because i need mobile compatibility and if i use the mouse position it will hit the shoot button on mobile. -
What solutions have you tried so far? I tried to fix it and looked on forums.
Can’t it originate from the Camera CFrame?
Also do you have by any chance a Humanoid in the Workspace, directly umder it?
No i don’t have any humanoid in my workspace, and i can’t originate the raycast from the camera CFrame it dosen’t take it
What you can do is to create a new camera, and set its CFrame to the center of the screen. Then shoot your ray out from there instead. If you are trying to make an full FPS game. you can also try to set that camera to player’s Head
and shoot the ray out from that camera.
That seems like a good idea, how would i set the new camera CFrame to the center of the screen tho?
Nevermind, there is no need to setup a new camara for this to work. Here is the idea.
So there is default camera that has been setup for you when the game is loaded. If you haven’t manually change the camera, the default camera can be accessed from workspace.CurrentCamera
you can try using ScreenPointToRay
and cast the ray from 2D Position in your screen to 3D position in world. Please do give it a try. Basically it will cast a ray from your currentcamera to 3D space.
Is that mobile compatible, like it wont shoot at the mobile shoot button right?
From what I believe, yes, it is mobile compatible. The reason is that the default camera is set in the middle of the screen (That’s why you can see things inside your experience) so the ray will shoot out from the camera to the direction that the camera is facing.
I’ve never tried implementing this, but it is a good approach.
Okay, thanks i will try that when i can