I have a scene, there is a cube with attached CharacterConrtoller and my script which you can see below.
Cube falls as wanted, but if I press any of WASD or arrows, it starts to fall much more faster. How to deal with it?
Watch screenshot of my scene. No scripts attached to Camera or Plain (click on 1.png in the bottom for full size)
Screenshots of Y-change without anything pressed and with W pressed:
http://i008.radikal.ru/1409/28/4c55ae5789af.png
http://i023.radikal.ru/1409/1e/0882ae1c41d4.png
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public float speed = 6.0F;
public float gravity = 0.0F;
private Vector3 moveDirection = Vector3.zero;
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent();
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
