Legacy Documentation: Version 2018.2 (Go to current version)
LanguageEnglish
  • C#

CharacterController.SimpleMove

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
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 if the character is grounded. It is recommended that you make only one call to Move or SimpleMove per frame.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(CharacterController))] public class ExampleClass : MonoBehaviour { public float speed = 3.0F; public float rotateSpeed = 3.0F;

void Update() { CharacterController controller = GetComponent<CharacterController>();

// Rotate around y - axis transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);

// Move forward / backward Vector3 forward = transform.TransformDirection(Vector3.forward); float curSpeed = speed * Input.GetAxis("Vertical"); controller.SimpleMove(forward * curSpeed); } }

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