• 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
-1
Question by klaasklompen · May 21, 2014 at 09:04 PM · ball

How do i move a 3D ball along the z-axis?

Hello there, I have a game in which you are a ball from the first person perspective. You can roll along the x-axis with w and s. I also want to move the ball along the z-axis with the a and d keys but i can't figure out how. I have tried many thing and looked at a lot of scripts but nothing worked. I hope one of you can help me.

Please any tips or hints would be amazing. Thank you in advance.

*update I edited the script to:

 #pragma strict
 
 var rotationSpeed = 100;
 var jumpheight = 8;    
     
 
 private var isFalling = false;
 
 function Update () 
 {
     
    var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
     rotation *= Time.deltaTime;
     rigidbody.AddRelativeTorque (Vector3.left * rotation);
    var rotation2 : float = Input.GetAxis ("Vertical") * rotationSpeed;
    rotation2 *= Time.deltaTime;
    rigidbody.AddRelativeTorque (Vector3.back *rotation2);
   
 
  if (Input.GetKey(KeyCode.Space)  && isFalling == false)
    {
            rigidbody.velocity.y = jumpheight;
    }
            isFalling = true;
 }    
 
 function OnCollisionStay ()
 {
     isFalling = false;
 }
 

And now it works thanks guys :D

Comment
Add comment · Show 1
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 Graham-Dunnett ♦♦ · May 21, 2014 at 09:06 PM 1
Share

Probably worth posting some of the scripts that you have written, and that don't work, and ask for advice on getting them to work. But I think you just want to replicate your lines 12/13/14 and modify those to work in the horizontal axis.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Hachley · May 21, 2014 at 09:14 PM

Just as Graham Dunnett ♦♦ stated.

add 3 more lines next to this:

 var rotation : float = Input.GetAxis ("Vertical") * rotationSpeed;
 rotation *= Time.deltaTime;
 rigidbody.AddRelativeTorque (Vector3.back * rotation); 

looking like this:

 var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
     rotation *= Time.deltaTime;
     rigidbody.AddRelativeTorque (Vector3.left * rotation); 

And by the way, you are moving on the Z axis with your W/S, and now will be able to move on the X with A/D. This is because Vector3.back stands for Vector3(0, 0, -1), which goes like (X, Y, Z). See Vector3 Documentation for more info.

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

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

22 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

Related Questions

Ball Falling Game. 2 Answers

how to rolle a ball by touch or mouse 0 Answers

rolling ball movement on different axis 0 Answers

how to make a player die on collision 2 Answers

Unrealistic bounce 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