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;[RequireComponent(typeof(CharacterController))]public class CharacterMover : MonoBehaviour{ private float speed = 3.0f; private float rotationSpeed = 90.0f; // degrees per second private CharacterController characterController; void Start() { characterController = GetComponent<CharacterController>(); } void Update() { float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); // Rotate character transform.Rotate(Vector3.up, horizontalInput * rotationSpeed * Time.deltaTime); // Move character Vector3 moveDirection = transform.forward * verticalInput * speed; characterController.SimpleMove(moveDirection); }}