Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by waltercl · Aug 24, 2021 at 04:55 PM · mousepositionmouselook

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image waltercl · Aug 30, 2021 at 03:18 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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;
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image waltercl · Aug 29, 2021 at 10:01 PM 0
Share

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.

avatar image waltercl · Sep 01, 2021 at 03:39 AM 0
Share

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.

avatar image rage_co waltercl · Sep 01, 2021 at 04:54 AM 0
Share

hmm, what method?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

125 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Use input.mouseposition to rotate camera 1 Answer

SpaceSim Mouse movement while upside down 0 Answers

Trying to achieve Enter The Gungeon type weapons but stuck on mouse rotation.,Trying to make a rougelike but stuck with making weapons face the mouse. 0 Answers

Variable is assigned but never used for ScreenPointToRay 1 Answer

rotate object to face mouse cursor along global y axis 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges