- Home /
Unable to locate Character Controller for sprinting.
I'm trying to have my character change from a normal walk speed to a sprinting speed but I'm getting a console error that reads: "An instance of type 'UnityEngine.CharacterController' is required to access non static member 'isGrounded'. I'm extremely new to Unity and scripting in general so I'm not really sure what this means or how to go about fixing it. I have my script in the inspector underneath my First Person Controller. Any insight would be helpful.
var walkSpeed : float = 7; //Regular Speed
var sprintSpeed : float = 13; //Running speed.
private var charMotor : CharacterMotor;
private var charController : CharacterController;
function Start ()
{
charMotor = GetComponent(CharacterMotor);
charController = GetComponent(CharacterController);
}
function Update ()
{
//Makes the speed variable.
var speed = walkSpeed;
//Checking if sprint is allowed.
if(CharacterController.isGrounded && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
{
//Changing speed to sprint.
speed = sprintSpeed;
}
charMotor.movement.maxForwardSpeed = speed; //Setting speed.
}
Answer by BigRoy · Jan 05, 2014 at 12:30 AM
Try:
charController.isGrounded
Instead of;
CharacterController.isGrounded
The first is pointing to the variable that you actually created, the other to the static class of CharacterrController in general which isn't anything in your scene.
Your answer
Follow this Question
Related Questions
How to stop character from running 2 Answers
Moving a character 1 Answer
Acceleration not parallel to the ground. 0 Answers
Player Controller "Horizontal" input convert to "left" and "right" 1 Answer