BASIC TELEPORTING QUEST: 'JumpyJumpy' - Solutions

Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.

1 Like

Hey Rick ! Thanks for the challenges !
So here is what I have done for this first challenger.

public class Bounce : MonoBehaviour
{
     [SerializeField] float jumpForce = 1000f;

     void OnTriggerEnter(Collider other)
     {
          JumpyJumpy(other);
     }

     void JumpyJumpy(Collider other)
     {
          other.attachedRigidbody.AddForce(0, jumpForce, 0);
     }
}

And really important here… if you don’t want to aim straight for the stars or even the moon… don’t forget to restet your Bounce component… it’s set to something like 7000 so you are going to fly pretty high.

2 Likes

Haha, I still a real kick out of seeing people first implement this and have their player get shot to the moon. :slight_smile:

1 Like

I didn’t get shot to the moon right away as I did something terrible first… I didn’t use a variable and put something like 500 right there in my method (I know, terrible sin).

But yeah when I changed to use jumpForce instead and I thought I had everything all neat and tidy… I was quite surprised to see my player take flight so dramatically. Serves me right for not paying attention :wink: !

public class Bounce : MonoBehaviour
{
    [SerializeField] 
    float jumpForce = 1000f;

    void OnTriggerEnter(Collider other)
    {
        // Challenge 1: JumpyJumpy(other);
        JumpyJumpy(other);
    }

    void JumpyJumpy(Collider other)
    {
        if(other.gameObject.CompareTag("Player"))
        {
            other.gameObject.GetComponent<Jump>().rigidbody.AddForce(Vector3.up * jumpForce);
        }
    }
}

First I’m checking if the player stepped on the bounce pad, and if so I’m adding force using the jumpForce variable.

2 Likes