Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to move?

Discussion in 'Getting Started' started by FireEnder1, Jun 30, 2015.

  1. FireEnder1

    FireEnder1

    Joined:
    Jun 30, 2015
    Posts:
    1
    I know absolutely nothing about Unity. I want to move a sphere with arrow keys. How would I do this? I have tagged it as player.
     
  2. sadsack

    sadsack

    Joined:
    May 27, 2015
    Posts:
    156
    try this,I am not sure where it came from.

    code/
    using UnityEngine;
    using System.Collections;
    public class FPSMove : MonoBehaviour
    {
    // Use this for initialization
    void Start()
    {
    }
    // Update is called once per frame
    public float speed;
    void Update()
    {
    speed = 0.1f;
    if (Input.GetKey(KeyCode.W))
    {
    transform.position += transform.forward * speed;
    }
    if (Input.GetKey(KeyCode.S))
    {
    transform.position -= transform.forward * speed;
    }
    if (Input.GetKey(KeyCode.A))
    {
    transform.position -= transform.right * speed;
    }
    if (Input.GetKey(KeyCode.D))
    {
    transform.position += transform.right * speed;
    }
    }
    }
    /code
     
  3. james_m_russell

    james_m_russell

    Joined:
    Jun 2, 2015
    Posts:
    25
    The very first tutorial teaches exactly this (moving a sphere). ;)
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,141
    Tags have no functionality on their own. You must make use of scripting to actually use them. I recommend simply starting with the tutorials in the Unity Learn section of this site. The Roll-a-Ball project has the closest to what you're looking for.
     
  5. ninja_pat

    ninja_pat

    Joined:
    Feb 20, 2015
    Posts:
    26
    Hi There,
    It really depends what you want to do in the end, and you might want to use built-in assets in some cases. If your goal is to be able to move a character around the virtual world, Unity already provides some very good built-in assets called Character Controllers. They can be imported as assets (Assets > Import Package > Character) and make it possible to navigate the scene through a First- or Third-Person using your keyboard and mouse. In other words, don't reinvent the wheel and use the assets provided by Unity, in many cases, these will get you started really quickly.
    If this something that you are trying to create (Character Controllers), I have created a step-by-step tutorial on this here. Give it a try and if you are still stuck, just give me a shout!
    All the best.