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 /
avatar image
1
Question by ace3df · Oct 04, 2011 at 08:59 PM · javascriptspherejavaball

Move a ball using keybored

Am trying to make a ball move by using my arrow or WASD keys. But I can't code 'at' all. How would one come across to do this? I have a Sphere with a "sphere collider" using Rubber material and the Sphere also has a rigid body. Thanks I will try and learn code but I can't :(

Comment
Add comment · Show 2
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 BiG · Oct 12, 2011 at 02:29 PM 0
Share

"keyboard", by the way. :)

avatar image Wolfrik_Creations · Jun 07, 2016 at 05:28 AM 0
Share

Yeah, my keys are really bored. $$anonymous$$aybe moving a ball would fix it.... I'm sorry, I had to xD

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by BiG · Oct 05, 2011 at 06:33 AM

You can use this script attached to your object to move it with arrow keys:

var speed = 5.0;

function Update () { var x = Input.GetAxis("Horizontal") Time.deltaTime speed; var y = Input.GetAxis("Vertical") Time.deltaTime speed; transform.Translate(x, y, 0); }

If you are trying to learn coding, I would explain it to you: First at all, speed is declared outside the function Update, so, it's an "exposed variable": you can access it from another script and even modify it from the Inspector View (attach it to the ball, click on the ball, and look in the right section of the screen: See "speed" value among all parameters of the ball?

Then, go to the function: it's an Update function, so it means that all the instructions inside it are performed every frame (other types of function exist: for example, function Start is performed once when the object is created).

Now, go to third instruction: "transform.Translate" translates the object in the point defined by x,y and z coordinates (z is 0 in my example).

How we defined x and y? By the 2 instructions above: considering x, we obtain it from the pressure of the related arrow key (Horizontal means left and right arrows, naturally), and from the speed time, that depends by the exposed variable "speed".

Try making experiments changing speed and the coordinate system (maybe, translate it on x and z, instead than x and y).

Note that, if you wanna use WASD, you need the Input.GetButtonDown function instead than Input.GetAxis. Look here: http://unity3d.com/support/documentation/ScriptReference/Input.GetButtonDown.html

The link that I've just reported it's a sublink of the scripting reference on the official site (a kind of scripting manual, in other words): you can learn a lot from it, so keep it in mind, when you need for an instruction!

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 liuqa · Jun 06, 2016 at 10:45 PM 0
Share

I have a question about that. Does it work on Unity 4 or do I have to upgrade it to Unity 5? I did everything according to the 2nd tutorial video, but it's not working.

avatar image
0

Answer by EvonneMeadows · Jul 01, 2015 at 05:32 AM

using UnityEngine; using UnityEditor; public class FindMissingScriptsRecursively : EditorWindow { static int go_count = 0, components_count = 0, missing_count = 0;

 [MenuItem("Window/FindMissingScriptsRecursively")]
 public static void ShowWindow()
 {
     EditorWindow.GetWindow(typeof(FindMissingScriptsRecursively));
 }
 
 public void OnGUI()
 {
     if (GUILayout.Button("Find Missing Scripts in selected GameObjects"))
     {
         FindInSelected();
     }
 }
 private static void FindInSelected()
 {
     GameObject[] go = Selection.gameObjects;
     go_count = 0;
     components_count = 0;
     missing_count = 0;
     foreach (GameObject g in go)
     {
            FindInGO(g);
     }
     Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
 }
 
 private static void FindInGO(GameObject g)
 {
     go_count++;
     Component[] components = g.GetComponents<Component>();
     for (int i = 0; i < components.Length; i++)
     {
         components_count++;
         if (components[i] == null)
         {
             missing_count++;
             string s = g.name;
             Transform t = g.transform;
             while (t.parent != null) 
             {
                 s = t.parent.name +"/"+s;
                 t = t.parent;
             }
             Debug.Log (s + " has an empty script attached in position: " + i, g);
         }
     }
     // Now recurse through each child GO (if there are any):
     foreach (Transform childT in g.transform)
     {
         //Debug.Log("Searching " + childT.name  + " " );
         FindInGO(childT.gameObject);
     }
 }

}

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 CBRZY · Jun 07, 2016 at 08:16 AM

Ok, obviously it would go a bit faster and be a bit easier if you have some coding experience, but don't worry, in my opinion Unity is probably the best engine to use in your case, because you will be able to make proper games without having to be a coding guru.

First of all, take a look at this tutorial for Unity, the create a game where you are moving a ball around with the keyboard https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial With this tutorial they also link the Unity manual when using Unity specific functions and features.

I would advise you to go through this live training session first though https://unity3d.com/learn/tutorials/topics/scripting/coding-unity-absolute-beginner This teaches you the basics of programming in the Unity IDE.

If you finish this training session and the tutorial on the rolling ball and you still enjoy it, then making games might be for you. Remember that coding isn't that easy. It will take some struggles to understand why something is or isn't working sometimes. This is just part of it, but don't give up, it gets easier... sometimes.

Good luck

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.

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

How to add aceleration to a sphere by pushing a key? 4 Answers

yield WaitForSeconds(); issue--very specific, apparently 2 Answers

Need a link to a Machine gun Script Please 1 Answer

Make a ball jump on plane collision 1 Answer

When in game, sound is really strange. Help Please!? 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