CharacterController.SimpleMove

Switch to Manual

Declaration

public bool SimpleMove(Vector3 speed);

Description

Moves the character with speed.

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 Move or SimpleMove per frame.

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); } }

Did you find this page useful? Please give it a rating: