BASIC TELEPORTING QUEST: 'JumpyJumpy' - Solutions

It is my solution:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// GameDev.tv Challenge Club. Got questions or want to share your nifty solution?
// Head over to - http://community.gamedev.tv

public class Bounce : MonoBehaviour
{
    [SerializeField] float jumpForce = 1000f;
    
    void OnTriggerEnter(Collider other)
    {
        // Challenge 1:
        JumpyJumpy(other);
    }

    void JumpyJumpy(Collider other)
    {
        if (other.name == "Player")
            other.attachedRigidbody.AddForce(0f, jumpForce, 0f);
    }
}

Of course in order not to jump "into the space"I decreased jumpForce ten times (700) in inspector.

Why does it seem like it doesn’t matter what I change the force to that I get launched beyond the clouds?

1 Like

How about the jumpForce = 0 ?
Check also parameters in Rigidbody (mass)!

and remember to set it in the unity editor. As it is a SerializeField the value from the Editor takes predesence to the one in the code

1 Like

Are you changing the jumpForce in the script or in the editor while clicked on the jump pad? Even though it is initialized as 1000 in the script, it’s been made a serialized field which gives you access to change it in the inspector which overrides what is initialized in the script. If you click on the jump pad, you should see it at 7000! I was also on cloud nine when I first touched the jump pad lol

Hi,

This is my version of the bounce script:

public class Bounce : MonoBehaviour
{

    [SerializeField] float jumpForce = 1000f;

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            JumpyJumpy(other);
        }
        else
        {
            Debug.Log("Did your forget to active the tag on player ?");
        }
    }

    void JumpyJumpy(Collider other)
    {
        other.GetComponent<Rigidbody>().AddForce(0f,jumpForce,0f);
    }
}

I spent a good quarter of an hour to understand why the “player” ignored the jump value and jumped way too high… now I think I won’t make this mistake again ^^

1 Like

Privacy & Terms