Gravity To CharacterController
Hi, I'm have issues adding gravity to the code below. Can someone please assist with this.
private var speed = 2.0;
private var pos : Vector3;
private var tr : Transform;
function Start() {
pos = transform.position;
tr = transform;
}
function Update() {
if (Input.GetKey(KeyCode.D) && tr.position == pos) {
pos += Vector3.right;
}
else if (Input.GetKey(KeyCode.A) && tr.position == pos) {
pos += Vector3.left;
}
else if (Input.GetKey(KeyCode.W) && tr.position == pos) {
pos += Vector3.forward;
}
else if (Input.GetKey(KeyCode.S) && tr.position == pos) {
pos -= Vector3.forward;
}
transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
}
Comment