I am developing a game that uses 3rd person view. The main camera is fixed and smoothly follows the character without any rotations. The x-axis is the depth of my map and the z-axis is the width. There is not suppose to be any movement in y-axis (no jumping). I’ve been troubleshooting this issue for a while and below is the script I am using currently for character control in the Update() function. The bazaar thing that is happening is that I get intermittent jumping of the character upon holding the “Vertical” input key. Sometimes it does not happen, sometimes it happens when moving the character back, sometimes when moving the character forward. When it starts to happen, if I hold the key down that causes the problem, the character will actually continue jumping up indefinitely until I release the key…then plummet back to the map. I am at a loss what could be causing this, as other than the else statement below (which was added later to try to stop this), I am not applying any position changes in the y-axis. I suspect that there is something internal to the character controller scripts that I am not aware of or I am passing a bad value (e.g. improperly casted or initialized variable) or something particular with Unityscript (which I am new to) as well that I have done incorrectly to have a runtime bug. I have gone through a bunch of tutorial code and searched online for others problems with the character controller, but do not seem to have done anything significantly different than others. Anyone else experience this issue? Thanks
var controller : CharacterController = GetComponent(CharacterController);
var moveDirection = Vector3.zero;
var forward = Vector3.zero ;
forward = transform.TransformDirection (Vector3.forward);
if (controller.isGrounded)
{
// rotate left/right around Y-axis
transform.Rotate(0,Input.GetAxis(“Horizontal”) * rotateSpeed * Time.deltaTime,0);
// Move forward/backward
controller.Move(forward * Input.GetAxis(“Vertical”)* speed * Time.deltaTime);
}
else
{
moveDirection.y -= 20*Time.deltaTime;
controller.Move(moveDirection);
}