A couple of ways to move object in Unity3d

I found there are not only one way to move object in Unity3d, So I collect some methods as notes, and as a post sharing.

Use Force

space shooter

Like this small sphere, it use force to move to change direction.

float moveH=Input.GetAxis("Horizontal");
float moveV=Input.GetAxis("Vertical");
Vector3 movement=new Vector3(moveH,of,moveV);
GetComponent<Rigidbody>().AddForce(movement*speed);

reference doc roll a ball tutorial

Use RigidBody’s Velocity

It is like the below, but change the last one to:

GetComponent<Rigidbody>().velocity=movement*speed;

Change RigidBody position directly

rb.MovePosition(transform.position+movement);

use Transform methods in Object’s transform

this.transform.Translate(Vector3.forward*speed*Time.deltaTime);

PS

the speed is a float varity.

And the below codes are just code snippets, you can not use them directly.