I am trying to convert my Character Controller jump over to AddForce ( ) jump. How would I do that given the following code?
controller.Move(Vector3.up * verticalVel * Time.deltaTime);
void CheckGrounded() { isGrounded = tryingJump ? false : (Physics.Raycast(transform.position + (transform.up * .05f), Vector3.down, .2f, groundLayerMask)); }
bool CheckUpperContact() { return (Physics.Raycast(transform.position + (transform.up * .5f), Vector3.up, 1.5f, groundLayerMask)); }
bool CheckForwardContact() { return (Physics.Raycast(transform.position + (transform.up * .7f), transform.forward, .5f, groundLayerMask)); }
void Jump() {
bool wasGrounded;
wasGrounded = isGrounded;
if (!canMove || speedBreak)
return;
if (!isGrounded)
{
StartCoroutine(JumpCoroutine());
return;
}
if (!isBoosting)
speedBooster.StopAll(false);
isGrounded = false;
verticalVel = Mathf.Sqrt(jumpHeight * -2f * gravity);
anim.SetTrigger("Jump");
StartCoroutine(JumpCoroutine());
IEnumerator JumpCoroutine()
{
tryingJump = true;
if (CheckForwardContact() && characterVelocity != 0 && !wasGrounded)
{
wallJumped = true;
direction *= -1;
characterVelocity *= -1;
verticalVel = Mathf.Sqrt((jumpHeight / 2) * -2f * gravity);
}
yield return new WaitForSeconds(.05f);
tryingJump = false;
yield return new WaitForSeconds(1);
wallJumped = false;
}
}
void Update()
{
desiredJump |= input.actions["Jump"].WasPressedThisFrame();
//Movement
CheckGrounded();
CheckDirection();
Move();
if (desiredJump)
desiredJump = false;
if (!isSliding)
Jump();
}
}
Thanks in advance for the help and have a VERY Merry Christmas!