Moving a sphere

Hello

I’m starting in Unity. I have been watching some tutorial about the program: Assets, Components, how to create a scene…

Now that I know the bases I want to start doing things and I have thought in a Sphere (or a Cube at this moment I don’t mind) which is moving on a plane according to the keys that are pressed.

I know how to get the keys, but I can’t find any tutorial (or something) that said how to simulate the movement.

Someone could help me? Thank you

You can make your sphere (or whatever) physical by adding a “Rigidbody” component to it. Then you apply some force with the “Rigidbody.AddForce” function. See the scripting reference on Rigidbody for some initial info.

You could also add a 3rd Person Controller and change the capsule to whatever you like.

There are several ways to move things - it depends on which thing you want to move.

In general, characters have a CharacterController component attached, and you move them using 1 or SimpleMove (you can find very useful examples in these topics).

You could also move a simple object (without CharacterController) with transform.Translate - but collisions are not detected, and the object just passes through the others.

Finally, you have the rigidbodies: adding a rigidbody to an object makes it obey the physics engine. It’s great to launch objects, or make them fall, bounce, hit other rigidbodies etc. - but not to control movement: when you apply a force, it accelerates the object while the force is being applied; when it’s removed, the object doesn’t stop - it continues moving due to its momentum, and you should apply a reverse force to make it slow down and stop.

The position of a gameObject is situated in gameObject.transfrom.position.

Do something like that:

void Update {
    if x input { //pseudocode for catching the key press event for moving in x direction
        transform.position = new Vector3(transform.position.x+20f,transform.position.y,transform.position.z);
    }
}

Untested but should work.