• 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 ringthane · Apr 28, 2014 at 09:43 PM · c#tagball

What should i put for the name of the z axis

My code needs the name of the axis to get (Input.GetAxis) I know horizontal and vertical for x and y but z im not sure I did try depth but that did not work.

Here is my code

using UnityEngine; using System.Collections;

public class player : MonoBehaviour {

 public float playerspeed =5.0f;

     // Use this for initialization
 void Start () {

     //Player Spawn Point

     transform.position = new Vector3 (0, 3, 0);
 
 }
 
 // Update is called once per frame
 void Update () {

     transform.Translate (Vector3.right * Input.GetAxis("Horizontal") * playerspeed * Time.deltaTime);

     transform.Translate (Vector3.forward * Input.GetAxis ("Z") * playerspeed * Time.deltaTime);
 
 }

}

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
1

Answer by monogon · Apr 28, 2014 at 11:46 PM

You can assign, rename and configure your axes in the Input Manager (Edit->Project Settings->Input). There is no Z-axis because this would not make sense. An axis just describes how the controller input is interpreted. For the joysticks it means that X-axis is horizontal movement (stick moved left or right) and Y-axis is vertical movement (stick moved up or down) by default, however everything is adjustable in the Input Manager.

Just get your movement on the z-axis from the input of the vertical axis!

 transform.Translate (Vector3.forward * Input.GetAxis ("Vertical") * playerspeed * Time.deltaTime);

But if you prefer, just go into the input manager and rename the vertical axis to "Z". ;)

Comment
Add comment · Show 2 · 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 aperez440 · Sep 30, 2017 at 02:14 PM 0
Share

$$anonymous$$onogon, I know this is an old post but this worked for me. I had the same issue as ringthane. $$anonymous$$uch appreciated.

avatar image diliupg · May 27, 2018 at 03:59 AM 0
Share

Worked for me too. $$anonymous$$any thanks!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

turn on off particle system 1 Answer

Making a bubble level (not a game but work tool) 1 Answer

C# change an object tag wit raycasthit. 2 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