Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SimpleMove(Vector3)

Moves the character with speed.
Read time 1 minuteLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.PhysicsModule
public bool SimpleMove(Vector3 speed)

Parameters

speed

Returns

Type

Description

bool

Remarks

Velocity along the y-axis is ignored. Speed is in units/s. Gravity is automatically applied. Returns true if the character is grounded. It is recommended that you make only one call to CharacterController.Move or CharacterController.SimpleMove per frame.

Examples

using UnityEngine;using UnityEngine.InputSystem;[RequireComponent(typeof(CharacterController))]public class CharacterMover : MonoBehaviour{ private float moveSpeed = 3.0f; private float rotationSpeed = 90.0f; // degrees per second public CharacterController characterController; [Header("Input Actions")] public InputActionReference moveAction; private void OnEnable() { moveAction.action.Enable(); } private void OnDisable() { moveAction.action.Disable(); } void Update() { // Rotate character transform.Rotate(Vector3.up, moveAction.action.ReadValue<Vector2>().x * rotationSpeed * Time.deltaTime); // Move character Vector3 moveDirection = transform.forward * moveAction.action.ReadValue<Vector2>().y * moveSpeed; characterController.SimpleMove(moveDirection); }}