Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 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 /
  • Help Room /
avatar image
0
Question by mothfruit · May 15 at 06:34 PM · camera rotatekeyboard inputcharacter controlling

how to rotate with arrow keys

i'm brand new to unity and c# so i'm completely in the dark right now

i'm trying to make some limited character movement so you can move forward and back with the up and down arrow keys and rotate side to side with the side arrow keys. i've got the forward and back part but i can't seem to get the rotation to work.

i've tried looking at a bunch of fixes for similar questions on here and youtube but none seem to work, possibly because they're outdated or i'm not putting the code in the right places.

not sure if this would be helpful but here's where i'm at right now

 void Start()
 {
 
 }
 
 void Update()
 {
     inputX = Input.GetAxis("Horizontal");
 
     if (inputX != 0)
         rotate();
 }
 
 void rotate()
 {
     transform.Rotate(new Vector3(0f, inputX * Time.deltaTime, 0f));
 }
Comment
Add comment · Show 4
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 rh_galaxy · May 15 at 06:40 PM 0
Share

You are rotating on Y, but with a very small value. inputX will be -1.0f .. 1.0f. You must decide a speed (degrees per second). Try

 float speed = 90.0f;
 transform.Rotate(new Vector3(0f, inputX * speed * Time.deltaTime, 0f));

And if you don't see anything, maybe you can try a different axis (Z?).

avatar image mothfruit rh_galaxy · May 15 at 11:21 PM 0
Share

thank you for your help, i added the change and now i'm getting an error that says "The name inputX does not exist in the current context." do you happen to know what it means?

avatar image rh_galaxy mothfruit · May 15 at 11:30 PM 0
Share

You do not have inputX declared in rotate() and not in Update() either. Get rid of rotate() and try

 public float rotationSpeed = 90.0f;
 void Update()
 {
     float inputX = Input.GetAxis("Horizontal");
     transform.Rotate(new Vector3(0f, inputX * rotationSpeed * Time.deltaTime, 0f));
 }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TheIrishKraken · May 15 at 10:31 PM

Do you have a screenshot of your character so I can visually see what your trying to do? So your character moves up and down on the Y axis but you only want him to rotate on the X axis and not move is that correct ?

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 mothfruit · May 15 at 10:51 PM 0
Share

alt text

alt text

i'm sorry i can't get a screenshot cause my file got messed up somehow so i'm currently starting over (luckily i didn't get that far lol)

hopefully the drawings explain it instead of making it more confusing. basically the character can only move forwards and backwards and if you want to go a different direction you rotate and then move forward

img-9444.jpg (37.1 kB)
img-9445.jpg (44.3 kB)

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

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

Have a UI Button do what my Input.GetButtonDown("Use") does? 0 Answers

Rotate ball in camera's direction.... 0 Answers

So I'm attempting to make a camera at a fixed angle with no rotation,I'm trying to set my camera on a follow path while keeping a fixed angle. 1 Answer

Camera rotation with mouse cursor 0 Answers

Rotate Camera using a joystick or buttons 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