I used to have a similar issue, I recommend raycasting from the mouse location on the screen and using that result.
Here’s an example:
local ray = camera:RayFromPosition(UserInputService:GetMouseLocation()) --not sure about the function name
local raycastResult = workspace:Raycast(ray.Orgin, ray.Direction, RaycastParams)
Note that this is only a part of the code.
Edit: Realized you didn’t want from the mouse position, but the screen middle. I suppose you can get the middle by getting the screen size. You would then put that instead of UserInputService:GetMouseLocation().
I want the arrow to spawn at bows location, then fly towards the screen center, but without the above mentioned issues occuring. Perhaps what is confusing you is the definition of screen center.
I dont want the arrow to fly to the screen center in 2D. I want the arrow to fly straight, but towards where player’s mouse is pointing, so that players can aim better.
its currently doing just that flying from the spawn location to the direction on the mouse position in 3D space and the mouse is positioned at the centre of the screen
here is another method that does not do what your asking for but does what i think you want it to do
I did do it with currentcamera look Vector, and with that arrow was moving perfectly fine, no matter where the character was. The issue with it is that i am offseting the camera, and because of that arrows fly lower than mouse cursor is, because camera look vector becomes lower than the actual screen middle
the thing is what your asking for is a paradox you want the arrow to fly in the direction the camera is facing but at the same time you want the arrow to fly to the mouse hit position
but them 2 directions are not the same so what your asking for is impossible
in the image above i show by shifting the camera so its over the arrow it will make the camera lookvector and mouse.hit.position align so that the arrow fly’s the way you want
if you don’t want to move the camera then we can move the hit position forward by 1000 while this is not the mouse.hit.position it might give a effect that your trying to achieve
local speed = 4
flyEvent.OnClientEvent:Connect(function(arrow)
local targetPosition = mouse.Hit.Position + mouse.Hit.lookVector * 1000
local direction = (targetPosition - arrow.Position).Unit
arrow.LinearVelocity.VectorVelocity = direction * speed
arrow.LinearVelocity.Enabled = true
end)
you can also change the 1000 value maybe something like 100 or 10 might be better
I understand, thank you for the detailed response. I actually tried offseting mousehitposition but to no avail, didnt try it the way you just showed, let me try and come back
The issue in the video disappeared, but arrow once again flies lower than the mouse cursor is. Perhaps we could change just the Z offset of mouse hit position? Or maybe make it fly to currentCameralookVector, but again with a given offset. It is just unclear to me how to apply offset to a lookvector, since it is not a normal vector3, but rather weird decimals that i have no clue how are calculated
this should be a mix of the cameras look vector and the direction to the mouse hit
local speed = 4
flyEvent.OnClientEvent:Connect(function(arrow)
-- get the cameraUpVector
local cameraUpVector = workspace.CurrentCamera.CFrame.UpVector
-- get the cameraRightVector
local cameraRightVector = workspace.CurrentCamera.CFrame.RightVector
-- get the directionUpVector
local directionLookVector = (mouse.Hit.Position - arrow.Position).Unit
local directionRightVector = cameraUpVector:Cross(directionLookVector)
local directionUpVector = directionLookVector:Cross(directionRightVector)
-- use the cameras right vector and the directions up vector to workout a new vector
local direction = cameraRightVector:Cross(directionUpVector)
arrow.LinearVelocity.VectorVelocity = direction * speed
arrow.LinearVelocity.Enabled = true
end)
Thank you so much for your consistent effort, I think this will work, unable to try right now since im at another location than the computer. Anyway marking as solution for now. I’ll try tomorrow, and if this doesnt work, ill mark as solution your answer that it is impossible.