Jump issue?

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!

Steps to success:

  • understand that CC is NOT compatible with RB. You may have one or the other. Otherwise they fight over the same Transform.

  • choose CC or RB

  • implement.

If you want a nice fully-functional super-basic starter prototype FPS based on Character Controller (BasicFPCC):

https://discussions.unity.com/t/855344

That one has run, walk, jump, slide, crouch… it’s crazy-nutty!!

That doesn’t answer my question at all. That is avoiding the question altogether. I’m NOT getting into a fight with you on Christmas Eve for crying out loud. I SPECIFICALLY asked, “using the following code, how do I change this 1 line ( controller.Move ) to use rb.AddForce” instead? Please stop giving me crap every time I post.

You’re establishing a long track record of hundreds of illogical posts, several of them verging on hysterical.

I hope that you can set aside your emotions and deal with the underlying software engineering problem.

It is clear you have not apprehended the first bullet point above.

Perhaps someone else can help you understand my first point above.

Steps to success:

  • remove the CharacterController

  • add a Rigidbody

  • reconnect all the movements you already have to instead manipulate the RB

  • choose a force or impulse value to use for your jump and connect to the jump.

With Physics (or Physics2D), never manipulate the Transform directly. If you manipulate the Transform directly, you are bypassing the physics system and you can reasonably expect glitching and missed collisions and other physics mayhem.

Always use the .MovePosition() and .MoveRotation() methods on the Rigidbody (or Rigidbody2D) instance in order to move or rotate things. Doing this keeps the physics system informed about what is going on.

https://discussions.unity.com/t/866410/5

https://discussions.unity.com/t/878046/8

Merry Christmas!

controller move handles your moving so you apply

You need to modify your controller. So the script you show us is not the controller.move(direction) function