I have created a simple player control. I have used "Vertical" and "Horizontal" axes as input to move. There is a character controller and I used this to move my player. But I don't know how to add a force as jump with space input. I am new to game development. Please help me to learn this. This is my script,
public class PlayerControll : MonoBehaviour { public Animator anim; public CharacterController characterController; public Rigidbody rb; public float Speed; public float Direction; Vector3 moveDir = Vector3.zero; float speedwalking = 8; float gravity = 8; void Start() { anim = GetComponent<Animator>(); characterController = GetComponent<CharacterController>(); rb = GetComponent<Rigidbody>(); } void Update() { if (characterController.isGrounded) { anim.SetBool("Grounded", true); if (Input.GetButton("Vertical") || Input.GetButton("Horizontal")) { Speed = Input.GetAxis("Vertical"); Direction = Input.GetAxis("Horizontal"); anim.SetFloat("Speed", Speed); anim.SetFloat("Direction", Direction); moveDir = new Vector3(Direction, 0, Speed); moveDir *= speedwalking; moveDir = transform.TransformDirection(moveDir); characterController.Move(moveDir * Time.deltaTime); moveDir.y -= gravity * Time.deltaTime; } else { anim.SetFloat("Speed", 0); anim.SetFloat("Direction", 0); } } else { anim.SetBool("Grounded", false); } } }