local arrow = ...
local targetPosition = ...
``` a vector3 describing the direction to the target position
local direction = targetPosition - arrow.Position
-- change this ratio to any number you like to change the flight curve
local ratio = 200 / direction.Magnitude
-- if you want to know how long it will take the arrow you get to its target
-- local throwTime = 1 / ratio
-- work out the force using gravity so it hits perfectly
local force = direction * ratio + Vector3.new(0, game.Workspace.Gravity * 0.5 / ratio, 0)
-- set the arrows velocity
arrow.AssemblyLinearVelocity = force
I saw your reply on the previous post. It unfortunately doesn’t give me much clue as to what to do, because my problem is exactly the targetPosition, which you did not give a value.
Currently my script sort of has a targetPosition, and it is Mouse.Hit.Position. My problem occurs when mousehitposition is too close to player, so instead of Mouse.Hit.Position, i need to use something else.
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