- Home /
FPS: Use Different type of Crosshair motion
I have a traditional FPS game where the crosshair moves with the main camera (which is attached to the player) and stays centered in the middle of the screen.
However, in one scene I want to have something similar to a traditional gunfight where the Player faces off against an enemy where both are standing still in a fixed position. In this scenario I want to only move the player's right arm holding a pistol and then have the crosshair move on the screen in the direction that the pistol is pointing. So at the beginning the pistol may be pointed almost down toward the ground and then you should be able to raise the arm with the mouse and put the crosshair on the enemy so you can shoot the enemy.
Then I need to be able to shoot a raycast to the point where the crosshair is.
I hope this makes sense what I'm asking.
So before implementing this part I started working on just moving the right arm around with the mouse and that isn't working like I thought it would. You can't just change the angle like you do with the camera, but I'm stuck on exactly how to do this part.
Answer by Llama_w_2Ls · Aug 28, 2021 at 05:42 PM
You should try transforming world points to screen points, to line up your crosshair with the hit position of your raycast. For example:
//... Raycast from pistol barrel in forward direction
// Transform the hit point in world space to screen space
Vector3 cursorPos = Camera.main.WorldToScreenPoint(hit.point);
CursorUI.transform.position = cursorPos;
Thanks for this feedback. I'm going to try and work on it soon. I'll let you know how it works out, and once I get something in place I'll be glad to mark this as the answer.
I've decided to this in another way because it was more of a pain to try and rotate the arm correctly with the mouse.