Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Hybris · Apr 19, 2017 at 10:53 AM · inputmousepositiontopdown

Synchronizing Fake Mouse Position with Actual Mouse Movement

Hello,

I'm working on a 2D top down shooter game, the controls are very similar to hotline miami. When I started on the aiming part I simply used Input.mousePosition, however this led to some difficulties.

When locking on to an enemy I had a texture, which normally has the same position on screen as the mouse, stay on that enemy until it died or it was no longer in sight. This meant that the mouse could move freely but the texture stayed on the enemy. As soon as the lock was broken the texture would shoot back to the actual mouse position and this could lead to a big sudden change in aim direction.

To combat this situation I locked the cursor instead of having it confined and used the following code to determine the position of the texture:

 public Vector2 fakeMousePos;
 
     private void Start() {
         fakeMousePos = new Vector2(Screen.width / 2, Screen.height / 2);
     }
 
     private void Update() {
         float mouseX = Input.GetAxisRaw("Mouse X");
         float mouseY = Input.GetAxisRaw("Mouse Y");
 
         fakeMousePos += new Vector2(mouseX, mouseY);
 
         if (fakeMousePos.x > Screen.width) fakeMousePos.x = Screen.width;
         if (fakeMousePos.x < 0) fakeMousePos.x = 0;
 
         if (fakeMousePos.y > Screen.height) fakeMousePos.y = Screen.height;
         if (fakeMousePos.y < 0) fakeMousePos.y = 0;
     }

I set the sensitivity of the Mouse Axis to be 1 because I thought this would mean that it would move at the same speed as it did in the operating system, this is not the case unfortunately.

I'm aware there is some kind of plugin that can change the mouse position in Unity, but I dont really want to use it unless I really have to. I have looked into the StandaloneInputModule, but I think this would just work when working with UI and a fake mouse position.

I would love to hear any ideas and possible solutions to the matter!

Thanks in advance,

Hybris

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

72 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

Related Questions

dash towards mouse position? (New Input System) 2 Answers

Problem with Vector3 Distance and Mouse Input, 1 Answer

How can I stop getting mouse position of Ui Elements? 0 Answers

How to check if mouse is above or below player? 2 Answers

Adding an offset to instantiated object based on mouse distance from player 1 Answer


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