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 Vampsz · Nov 03, 2019 at 06:53 PM · rotationsmoothquaternions

move based on camera position

I made a script to move around and it works decent, but the turns aren't smooth, they're instant and I can't figure out how to improve my code to make it smooth. I tried a couple of things with quaternions, but they're completely new to me and sofar I'm not getting close.

This is the code I'm trying to smooth out:

 if(vertical > _delay && horizontal > _delay)
         {
             transform.forward = _cameraController.transform.forward;
             transform.Rotate(0, 45, 0);
         } else if(vertical > _delay && horizontal < -_delay)
         {
             transform.forward = _cameraController.transform.forward;
             transform.Rotate(0, 315, 0);
 
         } else if (vertical < -_delay && horizontal < -_delay)
         {
             transform.forward = _cameraController.transform.forward;
             transform.Rotate(0, 225, 0);
         }
         else if (vertical < -_delay && horizontal > _delay)
         {
             transform.forward = _cameraController.transform.forward;
             transform.Rotate(0, 135, 0);
         } else
         {
             if (vertical > _delay)
             {
                 transform.forward = _cameraController.transform.forward;
             }
             if (horizontal > _delay)
             {
                 transform.forward = _cameraController.transform.forward;
                 transform.Rotate(0, 90, 0);
             }
             if (vertical < -_delay)
             {
                 transform.forward = _cameraController.transform.forward;
                 transform.Rotate(0, 180, 0);
             }
             if (horizontal < -_delay)
             {
                 transform.forward = _cameraController.transform.forward;
                 transform.Rotate(0, 270, 0);
             }
         }

Basicly, my character moves away from camera with W, towards camera with S, to the left of camera with A and to the right of camera with D. I managed to smooth it out some by adding an input delay, but it should be possible to improve this and I'd like to know how:)

Edit: This is still what I want to achieve, but I don't think the problem is my understanding of quaternions after looking into them some more. The thing I still can't figure out though, is how to properly relate this to say, the camera, or the cameracontroller. Here I'm using fixed numbers to turn a set amount after making sure my character faces forward, I have no clue how to change those fixed numbers into a variable related to my camera, which is the input I'd need for the quaternions if I'm not mistaken.

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

151 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 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

Choppy rotation of character around y-axis 1 Answer

Rotate a Cube on swipe gesture iOS, for a specific time? 0 Answers

Armature Rotation, lookAt on y axis, not z axis. 0 Answers

Why is my object not rotating smoothly ? C# 1 Answer

Issue with Slerping 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