Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
1
Question by Broccoli · Oct 11, 2010 at 08:43 AM · camerarotationquaternionlookatmouselook

Using MouseLook script with LookAt function

Hi,

I was trying to make a camera rotate like while using MouseLook script in the standard assert and I want a player can press a button to snap( LookAt ) a target in screen(First person view) while using MouseLook.

The problem is the MouseLook Script use quatenion to rotate in the following script

Code:

rotationX += Input.GetAxis("Mouse X") * sensitivityX; rotationY += Input.GetAxis("Mouse Y") * sensitivityY;

rotationX = ClampAngle(rotationX, minimumX, maximumX); rotationY = ClampAngle(rotationY, minimumY, maximumY);

Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up); Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);

FPSCamera.transform.localRotation = originalRotation xQuaternion yQuaternion;

and I try to use

Code:

FPSCamera.tranform.LookAt(target);

The thing that happen was my camera lookat target but the MouseLook still use the rotationX and rotationY that sum from before and try to wrap my camera back to where it was before using LookAt.

I know this would be a newbie question but How can I do this to make it get along together?

Thank you

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bill F · Nov 04, 2010 at 04:46 PM

Maybe obvious, but what happens if you fix the typo ("tranform") to this:

FPSCamera.transform.LookAt(target);

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

Answer by Aubrey Hesselgren · Jan 27, 2011 at 02:37 PM

Just after you use FPSCamera.transform.LookAt(target)*, you need to get the resultant rotationX and rotationY from the rotation you've forced, i.e. if you got the camera to look forward, then next time around, rotationX needs be 0, and so does rotationY... otherwise you're just setting the angles back to what the rotationX/Y is, which only gets changed by input, and not by whatever is doing your view snapping.

So I guess that you'd add something like

rotationX = FPSCamera.transform.localRotation.y;//because euler "Y" is yaw.
rotationY = FPSCamera.transform.localRotation.x;//because euler "X" is pitch.
Comment
Add comment · 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

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

How to add a rotation to this? 1 Answer

Camera X and Y velocity HELP! 0 Answers

Problem restoring proper camera rotation 1 Answer

How to make camera rotation relative to target. 3 Answers

Quaterion.Slerp + Lookat, camera flipping 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