Character dont jump
using UnityEngine;
// MoveBehaviour inherits from GenericBehaviour. This class corresponds to basic walk and run behaviour, it is the default behaviour.
public class Hannamove: MonoBehaviour
{
public float speednow = 1.0f;
public float walkSpeed = 2.0f; // Default sprint speed.
public float runSpeed = 2.0f; // Default sprint speed.
public string jumpButton = "Jump"; // Default jump button.
public float jumpnow = 10f;
public float jumpforce = 10f; // Default horizontal inertial force when jumping.
public float gravityyo = 10f;
private Vector3 dir = Vector3.zero;
//private
public bool jump; // Boolean to determine whether or not the player started a jump.
public bool isColliding; // Boolean to determine if the player has collided with an obstacle.
public Rigidbody playerrig;
// Start is always called after any Awake functions.
void Start(){
}
// Update is used to set features regardless the active behaviour.
//////////////////////
public void MoveInDirectionOfInput() {
//CharacterController controller = GetComponent<CharacterController>();
dir.x = Input.GetAxis("Horizontal");
dir.z = Input.GetAxis("Vertical");
///
Vector3 camDirection = Camera.main.transform.rotation * dir;
Vector3 targetDirection = new Vector3(camDirection.x, 0f, camDirection.z);
if (dir != Vector3.zero) {
transform.rotation = Quaternion.Slerp(
transform.rotation,
Quaternion.LookRotation(targetDirection),
Time.deltaTime * speednow);
///
}
/////////////////////////
if (!jump && Input.GetButtonDown(jumpButton)) {
jump = true;
jumpnow = jumpforce;
targetDirection.y = jumpforce;
}
//////////////
///////////jumpforce gravityyo
if (isColliding){
playerrig.velocity = targetDirection.normalized * speednow;
}
///
}
/////////////////////
void Update(){
MoveInDirectionOfInput();
}
/////////////////////////
// Collision detection.
private void OnCollisionStay(Collision collision){
isColliding = true;
jump = false;
}
private void OnCollisionExit(Collision collision){
isColliding = false;
//GetComponent<CapsuleCollider>().material.dynamicFriction = 0.6f;
//GetComponent<CapsuleCollider>().material.staticFriction = 0.6f;
}
}