• 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 raj727 · Jul 30, 2016 at 10:24 AM · movementz-axismovementshorizontal movement

X and Z axis question ?

Hey guys. So I am new to unity. bear with me. This is my code. I want the player to be set on position X and move on horizontal axis.. based on left and right inputs and in z direction / forward.. I have declared all the variables and included the header files. so this is my code..i am getting the following errors :

     private Vector3 playerPos = new Vector3 (0.25f, 0f, 2.23f);
 
 void Start () {

     player = GameObject.FindGameObjectWithTag ("Player");

     mainCamera.transform.localPosition = new Vector3 ( 0, 0, 0 );
     mainCamera.transform.localRotation = Quaternion.Euler (18, 180, 0);
 
 }
 
 // Update is called once per frame
 void Update () {

 //    player.transform.localPosition.x = posX;
     float moveAmount = Time.smoothDeltaTime * 10;

     if(mainCamera.transform.localPosition.z >= 0)
     {
         movementZ = Input.GetAxis("Vertical") * Vector3.forward * moveSpeed * Time.deltaTime;
         playerPos = new Vector3 (newX, 0f, movementZ);   // says this line has invalid arguments
                    // also says for the above line.. cannot convert vector 3 to float.. 
         player.transform.position = playerPos;
     }
     
 }

can you tell me what i am doing wrong.

thanks.

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
Best Answer

Answer by smnerat · Jul 31, 2016 at 04:47 AM

For the error on line 20. You are multiplying by Vector3.forward, which is why you can't set it equal to movementZ.

For the error on line 21, I don't see newX declared anywhere.

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 raj727 · Aug 16, 2016 at 08:42 AM 0
Share

thanks I got it.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

HOW TO MAKE A NPC GO FORWAR 0 Answers

2D Snail-like movement 1 Answer

How to make Z one directional? 1 Answer

How can i make it so that the object doesnt instantly go to top speed. Here is my code 1 Answer

What should i write that when i press "Shift" it will speed up idk how shift is named? Here's the code: 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