Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by Titus16 · Jun 26, 2012 at 04:36 AM · cubenoobmovingrolling

moving a cube

okay, so i literally am a noob, i only got Unity yesterday and have almost NO experience with it. i have a few very basic lines of code for JavaScript but aside from that i have no idea what im doing. Anyway, im trying to make a cube MOVE not ROLL. im using the arrow keys to control the cube but when i press left or right, the cube will begin to roll. Any help will be greatly appreciated

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Berenger · Jun 26, 2012 at 04:45 AM

So, the basics.

Animation is a modifaction of a parameter over time. Here you want the position to change when an input occures.

In Unity, you can create script that inherit from a certain class and attach them on a GameObject. Unity will then call specific functions at a specific times if you define them them in those script. The usual are Awake (All the awake functions are called first when the scene starts), Start (called once all the Awake are done) and Update (once per frame).

You need to modify the position of the cube each frame if the input is pressed. It's going to look like that :

 function Update() // The name matter. update() won't work.
 {
     // By using GetAxis, we use the InputManager. "Horizontal" is q/d or left/right and can be modified.
     //float h = Input.GetAxis( "Horizontal" ); // That's C#, silly me
     var h : float = Input.GetAxis( "Horizontal" );
 
     // Let's check if the input is pressed. Left is -1, right +1, nothing is 0
     if( Mathf.Abs( h ) > 0.0 )
     {
         // Now, we can move the cube by accessing the Transform component, which contains the matrix
         // To make the movement independant from the frame rate, we use Time.deltaTime.
         transform.position += Vector3.right * h * Time.deltaTime;
     }
 }
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
avatar image
0

Answer by Titus16 · Jun 26, 2012 at 11:09 AM

Thankyou for replying BUT.. i typed the code java and it came up with- Assets/Controls.js(8,9): UCE0001: ';' expected. insert a semicolon at the end

i had a quick scan through it and it says that it needs a semicolon in the

float h=Input.Getaxis ("Horizontal");

Again, any help and i will love you forever

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 The_Magical_Kiwi · Jun 26, 2012 at 11:18 AM 0
Share

Getaxis should be "GetAxis" you missed a capital A

http://unity3d.com/support/documentation/ScriptReference/Input.GetAxis.html

Always check you have typed everything in the right case, it's a mistake that can cause a lot of aggro especially if you are new to program$$anonymous$$g.

It might not be the answer to your current compiler error, but it is an issue that will stop your code from working.

Hope that helps.

avatar image Berenger · Jun 26, 2012 at 02:06 PM 0
Share

It's var h : float = Input.GetAxis( "Horizontal" );. As much as I try, C# always find it's way to come back at me ;)

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Everytime ball goes to new plane it bounces 2 Answers

Moving object between two points (script) 1 Answer

Cube Rotating & Moving 1 Answer

How can i stop a WASD Cube Player to move into nothing on a plattform? 2 Answers

Moving and rolling a cube 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