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 awplays49 · Oct 17, 2015 at 02:18 AM · rotationraycastlookatplane

Top down look rotation snaps when looking left, right, and back

Sure enough, these are the 3 directions the camera sees. The camera is moved back and up and angled down at 60 degrees. so it makes sense that only left right and forward are snapping. However, I have no idea why they are snapping in the first place. Heres my code:

 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             RaycastHit hit;
             if (Physics.Raycast (ray, out hit, 50, rayMask))
             {
                 Vector3 point = new Vector3 (hit.point.x, transform.position.y, hit.point.z);
                 transform.LookAt (point);
             }

So basically when I rotate a certain amount, it rotates another 20 or so degrees in a "snappy" fashion. its only when I look left right and at the camera. I am sure only the plane is in the cast mask.

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

1 Reply

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

Answer by C_Randy · Oct 17, 2015 at 04:38 AM

I did a similar thing with an xbox controller turning the player.

Get the LookAt position you want, in your case: point. Now save your current rotation: var rot = transform.rotation.eulerAngles. Give the transform the new lookAt point like you have. Now Lerp the rotation to smooth out the turning. eg. transform.rotation = Quaternion.Lerp(target rotation, current rotation, speed/smoothness).

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 awplays49 · Oct 17, 2015 at 12:36 PM 0
Share

Well after adding the lerp, it doesn't seem to turn towards the camera at all. Does this have to do with that my camera looks down but at a 60 degree angle?

 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             RaycastHit hit;
             if (Physics.Raycast (ray, out hit, 50, ray$$anonymous$$ask))
             {
                 Vector3 point = new Vector3 (hit.point.x, transform.position.y, hit.point.z);
                 Quaternion oldRotation = transform.rotation;
                 transform.LookAt (point);
                 Quaternion newRotation = transform.rotation;
                 transform.rotation = oldRotation;
                 transform.rotation = Quaternion.Lerp (transform.rotation, newRotation, rotationSpeed * Time.deltaTime);
             }
avatar image C_Randy awplays49 · Oct 17, 2015 at 11:51 PM 0
Share

This is what I used for a controller input:


if (Input.GetAxis(controls.RightStickX) != 0f || Input.GetAxis(controls.RightStickY) != 0f)
        {
            Vector3 lookAtPosition = transform.position + new Vector3(Input.GetAxis(controls.RightStickX), 0.0f, Input.GetAxis(controls.RightStickY));
            Vector3 rotation = transform.rotation.eulerAngles;
            transform.LookAt(lookAtPosition);
            transform.rotation = Quaternion.Lerp(Quaternion.Euler(rotation), transform.rotation, 0.2f);
        }

avatar image awplays49 · Oct 17, 2015 at 01:26 PM 0
Share

This only seems to happen on unet servers

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

33 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

Related Questions

SphereCast help 1 Answer

LookAt To Only Rotate on Y Axis 2 Answers

Make character look at mouse position, not world position 3 Answers

[HELP]Object Look At Raycast position 2 Answers

Rotate object to lookAt point and be perpendicular to the ground 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