so I made a bow and it shoots arrows, suprize yeah. But i have no clue on how to aim that bow. it works perfectly just i dont know how to get it to shoot to the crosshair.
i know that the crosshair is on the camera and not in the game or whatever. i can get the exact vector location that i want the arrow to hit using a line cast by channel but i dont know how to tell the projectile to hit that vector (target) .
all the crosshair shooting i find on the internet have linecast fake bullets, and all the real physical projectiles i find dont use any crosshair whatsoever.
now i can change the pitch of the bow and set initial velocity after finding the straight line distance to the target that i get from the linecast using the equations of projectile motion from high school. but i have a feeling that that would be hugely unnecessary.
So no one answered. This is for someone who might have the same problem.
Make the raycast(by chanel) from camera to get location of the hit, using that location with the location of your weapon calculate vector from weapon to target, get it’s unit vector, multiply with your desired velocity(float) and then set this resulting vector as your projectile velocity. Now the projectile will travel to crosshair. This will also work if you have gravity enabled, just the projectile will drop according to the velocity you multiplied with the unit vector and the distance to target.
This method has a flaw however- I’m working on a solution. This works perfectly indoors but the raycast won’t collide with skysphere so if you are outside and aim to the sky the raycast will return 0,0,0 and your weapon will shoot towards your world origin.
If you have any doubt you can comment.
Solution 1- check for this case before setting velocity and if this was about to happen then don’t use the raycast and simply shoot straight with weapon forward vector.
Solution 2- make a gigantic sphere with inside collision (I don’t know how to do that yet)and put sky material on it .
Solution 3- wait for me to find a solution.