Loading lessons...
Joints & Character Controllers
Joints & Character Controllers
Physics Joints
Joints connect Rigidbody components together to simulate complex physical structures like hinges, chains, or suspensions:
- Hinge Joint: Restricts movement to rotation around a single axis (like a door hinge).
- Fixed Joint: Restricts all movement, keeping two Rigidbodies locked together.
- Spring Joint: Connects two objects with a spring force that pulls them back if they move apart.
Character Controller
For player characters, using standard Rigidbody physics can lead to issues (characters sticking to walls, bouncing randomly, or sliding on slopes).
Unity provides a Character Controller component designed specifically for third-person or first-person movement.
- It does not use a Rigidbody.
- It is unaffected by gravity or forces automatically; you must apply gravity in your scripts.
- It features built-in collision checks to walk up steps and slide smoothly along walls.
Movement Script with Character Controller:
public class PlayerMove : MonoBehaviour
{
private CharacterController controller;
public float speed = 5.0f;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
// Move the controller
controller.Move(move * speed * Time.deltaTime);
}
}
TL;DR
- Joints link Rigidbodies with relative constraints (Hinge, Fixed, Spring).
- Character Controller provides collision-driven character movement.
- Character Controllers ignore standard physics forces and require manual script gravity calculations.