How Unity moves in summary

Source: Internet
Author: User

1. Introduction

In Unity3d, there are many ways to change the coordinates of an object, to achieve the purpose of moving, its essence is to modify the position of the object every frame.

2. Moving objects through the transform component

The Transform component is used to describe the state of an object in space, including position (position), rotation (rotation), and scaling (scale). In fact, all movements lead to position changes, as described here by moving objects through the transform component, referring to the direct manipulation of the transform to control the position of the object (position).

2.1 Transform.translate

This method moves the object from its current position to the specified position, and can select the coordinate system of the reference. When you need a coordinate system transformation, consider using this method to omit the steps to convert the coordinate system.

Public function Translate (Translation:vector3, relativeto:space = space.self): void;

2.2 Vector3.lerp, Vector3.slerp, vector3.movetowards

Vector3 can represent either a point in a three-dimensional space or a vector. These three methods are interpolation methods, Lerp is linear interpolation, Slerp is spherical interpolation, movetowards on the basis of LERP added limit maximum speed function. These methods can be considered when you need to move from the specified point A to point B.

2.3 Vector3.smoothdamp

The method can be smoothed from a gradually to point B, and can control the speed, the most common use is the camera to follow the target.

2.4 transform.position

Sometimes re-assigning position can achieve our goals faster.

3. Moving objects through the Rigidbody component

Rigidbody components are used to simulate the physical state of an object, such as when an object is affected by gravity, when the object is hit by a collision, and so on.

Note: Calls to Rigidbody should be placed in the Fixedupdate method, which is called every time a physical simulation is performed.

3.1 rigidbody.velocity

Setting the body speed allows the object to move and ignore the static friction, which causes the object to move quickly from the stationary state to the motion state.

3.2 Rigidbody.addforce

A force that adds a direction to a rigid body, which is suitable for simulating the motion of an object under external forces.

3.3 Rigidbody.moveposition

When a rigid body is physically constrained, move to a specified point.

4. Moving objects through the Charactercontroller component

Charactercontroller is used to control the movement of first-person or third-person characters, which can be used to simulate human behavior, such as limiting the maximum slope of a character's climb, the height of the pace, etc.

4.1 Charactercontroller.simplemove

For simulating simple motion and automatically applying gravity, the return value indicates whether the role is currently on the ground.

4.2 Charactercontroller.move

To simulate more complex motions, gravity needs to be implemented by code, and the return value represents the collision information between the character and the surrounding.

How Unity moves in summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.