How to jump to platform by clicking on it

right now, I have my game set up intended for mobile. My character is the character controller. There is no gravity and no movement.

Character jumps to a platform when space bar is pressed and character automatically jumps at a fixed rate going from platform to platform. Platforms can’t be skipped and players must jump through sequentially.

Instead of space bar, I want to figure out how i can click a specific platform and have the character go there to the platform I click. I want the platform that the player is supposed to jump on to be glowing and stop glowing afterwards.

If anyone can help me i would appreciate it :slight_smile:



Test build here: Dropbox - Web.html - Simplify your life

This is what I have now for code:

public class Jump : MonoBehaviour

    CharacterController motor;

    public float maxJumpPower = 50; //Initial velocity for jump
    public float jumpPower = 0; // Current velocity for jump

    public float gravity = 0.75f;   //  Jump velocity reduced each frame
    public float maxFallSpeed = -20f;    //  Maximum velocity for fall- Limited to prevent falling through platforms
    bool isJumping = false; // Is the character jumping? Only move while jumping
    bool movingRight;   //  The character will move to the right or to the left only

    public float maxRunSpeed = 5;   //  The character will have its speed set to this if it is moving right, or this * -1 to move left
    float runSpeed = 10f; // Current speed

    void Start()
        //  Get the CharacterController attached to the gameObject that this script is attached to
        motor = gameObject.GetComponent<CharacterController>();

    void Update()
        //  if the character is on the ground, he must not be jumping
        if (motor.isGrounded)
            isJumping = false;

        // if the character isn't jumping and they press jump, start them at full speed
        if (Input.GetKeyDown(KeyCode.Space) && isJumping == false)
            isJumping = true;
            movingRight = !movingRight;
            jumpPower = maxJumpPower;

        //  reduce jump velocity by gravity every frame
        jumpPower -= gravity;
        if (jumpPower < maxFallSpeed)
            jumpPower = maxFallSpeed;

        // Set the proper speed for moving right or left
        if (movingRight)
            runSpeed = maxRunSpeed;
            runSpeed = -maxRunSpeed;

        //  If the character is jumping, move it. X is horizontal, and Y is vertical
        if (isJumping == true)
            Vector3 moveVector;

            moveVector = new Vector3(runSpeed * Time.deltaTime, jumpPower * Time.deltaTime, 0);



For me the shorter way to do that is firstly to create a script implementing OnMouseDown function. After that you can attach this script to each platform and easily call a function from Your game controller when a platform is clicked.

public class PlatformController: MonoBehaviour
  // The jump script
  private Jump  _jump;

  void Start() {
    // Find in the scene the jump script.
    _jump = GameObject.FindGameObjectWithTag("JumpEmptyGameObject").GetComponent< Jump >();

  void OnMouseDown () {
    // call your function witch will make glowing the platform and make jump...


I hope this help…