unity nine kinds of methods to move

The first is simply to control the movement of the object
moving from one location to another
transform.position += new Vector3(0, 0, 10);
second: a method, delegate call is available

transform.Translate(new Vector3(0, 0, 10));

The third Vector3 .MoveTowards have uniform motion of the target point, when the destination point has been movement.

transform.position = Vector3.MoveTowards(transform.position, obj.transform.position, 0.5f);

Fourth linear interpolation deceleration target point of the movement, and better smooth movement
commonly used in the camera to follow,

Vector3.Lerp(Camera.main.transform.position, new Vector3(Mathf.Clamp(posX, 0, 15) 

Fifth Vector3.Slerp (spherical movement difference motion deceleration target point to be noted here that when two objects from the nearly spherical motion is not so obvious difference, the more obvious the farther the distance difference of spherical curvature.

transform.position = Vector3.Slerp(transform.position, obj.transform.position, 0.01f);

Sixth: rig.AddForce add force to an object, the equivalent of a bullet, give him a moment of force, so that he moves forward

 public   Rigidbody rig; 
 void FixedUpdate (){
rig.AddForce(new Vector3(0.1f, 0, 0.1f), ForceMode.VelocityChange);

}

Seventh rig.velocity object to add speed


rig.velocity -= new Vector3(0.1f, 0, 0.1f);

Eighth
cc.move character controller, slow moving, without simulated gravity

 public CharacterController aa;
 void FixedUpdate (){
aa.Move(new Vector3(0.1f, 0, 0.1f));
}

Ninth

aa .SimpleMove(new Vector3(0, 0, 11.1f));

The above method is what we used to move it.

Guess you like

Origin blog.csdn.net/weixin_44370124/article/details/90080871