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 Fallenleader · Jul 10, 2016 at 05:22 PM · movement scriptgetaxis

[Unity 5] GetAxis("Horizontal") Causes player to move the opposite direction

http://answers.unity3d.com/questions/550988/my-movement-keys-are-opposite-to-actual-movement.html

My issue is exactly the same as in this thread. In my code, the player can rotate. this part works as desired. I can move vertical just fine, but horizontal movement makes me move the opposite direction (e.g. I move right when I press left) My code is this: using UnityEngine; using System.Collections;

 public class PlayerController : MonoBehaviour
 {
     private float speed = 1f;
     public Transform playergraphic;
 
     void Update()
     {
         ControllPlayer();
     }
 
     void ControllPlayer()
     {
         float horMovement = Input.GetAxis("Horizontal");
         float vertMovement = Input.GetAxis("Vertical");
         if (horMovement != 0 && vertMovement != 0)
         {
             speed = 3.0f;
         }
         else
         {
             speed = 1.5f;
         }
         transform.Translate(transform.right * horMovement * Time.deltaTime * speed);
         transform.Translate(transform.forward * vertMovement * Time.deltaTime * speed);
 
         //Player graphic rotation
         Vector3 moveDirection = new Vector3(horMovement, 0.0f, vertMovement);
         if (moveDirection != Vector3.zero)
         {
             Quaternion newRotation = Quaternion.LookRotation(moveDirection);
             playergraphic.transform.rotation = Quaternion.Slerp(playergraphic.transform.rotation, newRotation, Time.deltaTime * 8);
         }
         //Player graphic animation
         /*if (moveDirection.magnitude > 0.05f)
         {
             playergraphic.GetComponent<Animation>().CrossFade("walk", 0.2f);
         }
         else
         {
             playergraphic.GetComponent<Animation>().CrossFade("idle", 0.2f);
         }*/
     }
 }

I have tried multiple "solutions, but nothing works. I can manually force input from keys, but this kills the option for a controller, and would make my investment in one for testing reasons a waste. Is this a issue in the latest build of Unity 5?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to Rotate my spaceship on the Y axis or turn it around but not right around like half using the horizontal 0 Answers

How can I simulate the smoothness of the Input.GetAxis? 0 Answers

how to make the player move in only 2 directions? 0 Answers

Pressing the key once, moving up, down, left or right until meet the wall. 0 Answers

Assets/ballcontrol.js(3,5): UCE0001: ';' expected. Insert a semicolon at the end. 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