AnswerBun.com

How can you make a jump to a point using the Character Controller?

Game Development Asked by Aimon Z. on December 25, 2020

I found an example with which the CharacterController can jump, but it does not work to remake it so that it jumps to a certain point/distance, and the jumpHeight itself was calculated for speed and gravity, I found this article on Wikipedia, but I don’t even know why to begin.

public class ExampleClass : MonoBehaviour
{
    public float speed = 6f;
    public float jumpHeight = 8f;
    public float gravity = 20f;

    private Vector3 moveDirection = Vector3.zero;

    CharacterController controller;

    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    void Update()
    {


        if (controller.isGrounded)
        {
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= speed;
            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;

        }
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
    }

    // Method for jump, calling from other script.
    void Jump(float pointX)
    {
    }
}

I can’t find examples for the Character Controller, although I did find one for the Rigidbody.

Add your own answers!

Related Questions

My GameObject keeps spawning when it shouldn’t

2  Asked on November 9, 2021 by michael-hampshire

     

Texture blends into one single color

1  Asked on November 9, 2021 by andrey-k

       

Player jitters when Jumping at object edges

1  Asked on November 9, 2021 by cgaudet

   

My bullets won’t bounce in Unity?

1  Asked on November 6, 2021 by kayra-yorulmaz

     

How to time draw images to the window in d3d8

0  Asked on November 2, 2021 by kite

 

Tank / turret animations

0  Asked on November 2, 2021 by lilkrit

   

Problems with recursive backtracking algorithm for a 3D maze

0  Asked on November 2, 2021 by janis-taranda

   

Add a sound to all the buttons in a project

3  Asked on November 2, 2021 by hamza-memon

   

Editing terrain in Blender

0  Asked on November 2, 2021

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP