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 Baxter · Jan 24, 2010 at 10:01 PM · camera

Default Mouse Look Script

Hello All,

I have a 3rd person camera on the go with the stardard MouseLook script on my player controlling the X axis and a standard MouseLook script on the camera controlling the Y axis.

What I need is for the cursor to ALWAYS be centered in the middle of the screen. Can this be done? If so can you help me with some example code or point me in the right direction please?

Many thanks in advance!

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

3 Replies

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

Answer by runevision · Jan 26, 2010 at 03:11 PM

Use "Screen.lockCursor = true". In standalone games you can do this anywhere, and it should work.

In a webplayer you are not allowed to lock the cursor before the user has clicked somewhere inside the webplayer area, so it's better to set Screen.lockCursor = true whenever you get a mouse-down (if you still want to lock the cursor).

Note that even if the cursor is successfully locked, it will be unlocked again if the user presses ESC. This is why it's a good idea to lock it whenever you get a mousedown. This way the user can free the mouse by pressing ESC, but then get the mouse locked again by pressing inside the webplayer area again.

Comment
Add comment · Show 1 · 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 Baxter · Jan 27, 2010 at 08:50 AM 0
Share

thank you for your input. I am not going to be having this game in a webplayer, it will be a standalone game. the Screen.lockCursor - true seems to lock the mouse inside the game screen, but I need it locked constantly to the center of the game screen - is there some additional code for this?

avatar image
2

Answer by Duke · Jan 26, 2010 at 05:05 PM

Given that locking the mouse cursor in the webplayer is problematic, one possibility you may want to consider is having a crosshair that operates separately from the mouse cursor in your 3rd person mode, such as by drawing one in the OnGUI() event.

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 Baxter · Jan 27, 2010 at 08:52 AM 0
Share

thanks for you input. As of yet I have not learnt about this OnGUI() event - if you have any links to tutorials or anything would be much appreciated :-) want to learn as much as possible :-)

avatar image Duke · Jan 27, 2010 at 05:18 PM 0
Share

I learned about OnGUI() (and a lot of other things) in the 3rd person platformer tutorial. Hopefully it can help you out as well.

http://unity3d.com/support/resources/tutorials/3d-platform-game

avatar image Baxter · Jan 28, 2010 at 12:56 PM 0
Share

Ahhh great to know thank you!

avatar image
0

Answer by Eric5h5 · Jan 24, 2010 at 10:08 PM

Use "Screen.lockCursor = true".

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 Baxter · Jan 25, 2010 at 05:42 PM 0
Share

Thank you for your reply! I have put the Screen.lockCursor = true in the mouseLook script and do not recieve any errors, but it does not lock the cursor. Whereabouts in the script do I need to put this...does it matter where? Sorry very boobish in program$$anonymous$$g.

Thanks in advance

avatar image Eric5h5 · Jan 25, 2010 at 10:51 PM 0
Share

As long as that command is run somewhere, it should work.

avatar image Baxter · Jan 26, 2010 at 01:08 PM 0
Share

again thanks for your reply. Unfortunately it's not doing what I wanted it to. If I move the move right then stop, my character is facing forward, but the mouse cursor is still not central.

$$anonymous$$aybe I was unclear as to what I am trying to achieve. If anyone has ever played the new Call Of Duty game - when you unlock 3rd person games in multiplayer you'll notice the crosshair will ALWAYS stay center of the screen. Hope this makes sense and sorry if I am being dumb! As I said before very new to all this xD

thanks again in advance for all your input

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Using the accelerometer to rotate Camera 1 Answer

Need help with script, one time touch to the screen = synchronize camera with face 0 Answers

How to apply target, while created at runtime? 1 Answer

Backgrounds moving at different speeds? 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