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 Asafl14 · Nov 12, 2015 at 04:35 PM · character controller

How can I rotate a character 180 degrees by D, and -180 by A

I try to move a 3d character like a 2d character in a platform game. What I mean is; when I press D, the character rotate and move to the right , and when I press A, the character rotate and move to the left . I was thinking to reference the local axis of the character to the world axis && press A,D than rotate 180 degrees, else - stay your current direction . I dont know if its the way to do it, and I dont know how to code it. Im new to c#/ 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
2

Answer by killer-zog · Nov 12, 2015 at 11:13 PM

just wrote a quick demo for you. Basically it takes two keyboard input: 1. when user press A and B it uses transform.Rotate method, while passes a vector as it's rotation direction and speed.

 using UnityEngine;
 using System.Collections;
 
 public class rotate : MonoBehaviour {
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKey(KeyCode.A))
         {
             rotateMove(-1);
         }
         else if (Input.GetKey(KeyCode.D))
         {
             rotateMove(1);
         }
     }
 
     private void rotateMove(int dir)
     {
         gameObject.transform.Rotate(0, dir, 0);
     }
 }
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
0

Answer by Asafl14 · Nov 15, 2015 at 10:00 AM

Thanks a lot, realy appreciate your answer, I come from the world of 3d, not scripting, if you need anything - help with modeling ,texturing...whatever I can help, just ask.

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 killer-zog · Nov 15, 2015 at 11:10 AM 0
Share

well ins$$anonymous$$d of a new answer you could just use Add Comment link under my answer. But anyway, glad to help. I am also from $$anonymous$$aya, didn't had any scripting knowledge whatsoever just learned couple months ago, now Unity seems a lot EASIER!

If it did help you might wanna accept my answer as accepted answer. :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Make a gameobject with a character controller inivisble 2 Answers

how can I make a character fly when holding down the jump button? 1 Answer

Character strafing problem (javascript) 0 Answers

Character Movement not moving how i want 2 Answers

Moving along relative z axis with character controller? 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