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 /
  • Help Room /
avatar image
0
Question by Asdf11x · Jun 08, 2016 at 11:43 PM · topdowntop-downtop downdowntop

Top Down Keyboard Smooth rotation

Hi,

Im sorry I know this question was posted many times, but every solution I try, it wont work out :(((( im kinda desperate right now...

I have a top down game (axis) : y -> up/down, x -> left/right, z->in/out (not used for game)

Now the Controls:

 float moveH = Input.GetAxis("Horizontal");
 float moveV = Input.GetAxis("Vertical");

I want my playermodel turn into the keyboard direction. Best would be that when the player is facing top he has to do a half circle to go down, but that would be a luxury...

my solution:

 Vector3 top = new Vector3(transform.position.x, transform.position.y + 10F, transform.position.z);
 Vector3 down = new Vector3(transform.position.x, transform.position.y -10F, transform.position.z);
 Vector3 left = new Vector3(transform.position.x-10F, transform.position.y, transform.position.z);
 Vector3 right = new Vector3(transform.position.x+10F, transform.position.y, transform.position.z);
 
 if(Input.GetKey(KeyCode.UpArrow)){
     transform.LookAt(top);
 }
 if(Input.GetKey(KeyCode.DownArrow)){
     transform.LookAt(down, -Vector3.forward);
 }
 if(Input.GetKey(KeyCode.LeftArrow)){
     transform.LookAt(left, -Vector3.forward);
 }
 if(Input.GetKey(KeyCode.RightArrow)){
     transform.LookAt(right, -Vector3.forward);
 }

Every solution I tried f***ed my axis up. I never met the right ones... Except exactly this one

Would be great if anyone could help me

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

Answer by Asdf11x · Jun 09, 2016 at 09:17 AM

I made a solution which works. Its pretty straight forward. But it isnt possible to have you character look only a bit to one side. The player will always rotate fully to the given coordinates, maybe I m gonna find out how it works, to rotate only a little bit. But this is great for now

 if (Input.GetKey (KeyCode.UpArrow)) {
                 qTo = Quaternion.Euler (-90, 0, 0);
             }
             if (Input.GetKey (KeyCode.DownArrow)) {
                 qTo = Quaternion.Euler (90, 180, 0);
             }
             if (Input.GetKey (KeyCode.LeftArrow)) {
                 qTo = Quaternion.Euler (0, 270, 90);
             }
             if (Input.GetKey (KeyCode.RightArrow)) {
                 qTo = Quaternion.Euler (0, 90, 270);
             }
             if (Input.GetKey (KeyCode.UpArrow) && Input.GetKey (KeyCode.LeftArrow)) {
                 qTo = Quaternion.Euler (315, 270, 90);
             }
             if (Input.GetKey (KeyCode.UpArrow) && Input.GetKey (KeyCode.RightArrow)) {
                 qTo = Quaternion.Euler (315, 90, 270);
             }
             if (Input.GetKey (KeyCode.DownArrow) && Input.GetKey (KeyCode.LeftArrow)) {
                 qTo = Quaternion.Euler (45, 270, 90);
             }
             if (Input.GetKey (KeyCode.DownArrow) && Input.GetKey (KeyCode.RightArrow)) {
                 qTo = Quaternion.Euler (45, 90, 270);
             }
     
             transform.rotation = Quaternion.RotateTowards (transform.rotation, qTo, speedQuad * Time.deltaTime);


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

57 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

Related Questions

How to make an skidmarks system on a 2D top-down car sprite? 0 Answers

2D Animations in Unity with multiple Sprites 0 Answers

[2D] Make player push object 1 Answer

2D Movement Controls Like a Dying Fly 0 Answers

LookAt method is stuck on one axis, Why? 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