A simple rigidbody function doesnt work.


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”.

Hi, I guess the controller.Move called later just cancels all forces you previously added. In the ChracterController documentation, there is an example with a “jump” done by modifying the Vector passed to controller.Move, without using AddForce. You may want to try this. Unity - Scripting API: CharacterController.Move