Hey.
using UnityEngine;
using System.Collections;
public class move : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController> ();
Rigidbody rigidbody = GetComponent<Rigidbody>();
if (controller.isGrounded) {
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= speed;
}
if (Input.GetKey (KeyCode.Space)) {
rigidbody.AddForce (0, 200, 0);
print ("nanana");
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
Everything but the “ridigbody.addforce” does work here. Could someone please help me why it doesnt work?
Oh, and the “print” function works, so it is not a problem with “if”.
Thanks for the answer. Im trying to modify the code you linked here so I can control my character in air. There are so many threads about this, but I havent found any working one. Not using rigidbody here would be cool, but I dont have any other idea how to control the character in air.
– Jujek