how to create a jump pad?!?

Hi there,
I hope someone can help me a bit…

I want to create a jump pad when the player enters a collider he should get a vertical boost

My Player is instantiated at runtime without a rigidbody and I have attached the following Script to a Cube with a Box Collider (is Trigger = active) BouncePad is also activ

I have no errors in the console but nothing happens…

I would appreciate if anyone has an idea how to achieve that!

using UnityEngine;

namespace TheKit
{
    /// <summary>
    /// Use this to apply damage or kill player with triggers
    /// </summary>
    public class Kit_PlayerTriggerZone : MonoBehaviour
    {
        public bool BouncePad;
        [Tooltip("BouncePad?")]
        /// <summary>
      
        public float AmountOfForce = 20;

        private void OnTriggerEnter(Collider other)
        {
            Kit_PlayerBehaviour pb = other.transform.GetComponent<Kit_PlayerBehaviour>();
            if (pb)
            {
                //Check if its our
                if (pb.photonView.IsMine)
                {
                    if (BouncePad)
                    {
                        other.transform.TransformDirection(Vector3.up * AmountOfForce);

                    }
            
               
                   }
             }
    }
}
}

You will need a Rigidbody on the object with the Collider set to isTrigger == true.

thanks for your reply… you mean on the jump pad itself?
I tried that too, it doesnt work taht way…

He meant on the player.
If the player has a rigidbody, you can just do other.GetComponent().AddForce(Vector3.up * AmountOfForce) to bounce the object upwards.

You dont necessarily need a Rigidbody tho. It depends on how you handle your player movement. If you maintain your own velocity vector you can add the force to that manually. If the game is mostly physics based anyways a rigidbody would be the correct approach tho.

One main problem with your current approach is that you seem to misunderstand TransformDirection. It does absolutely nothing in your current context. Transform.TransformDirection(Vector3 direction) transforms the given Vector3 from local space to world space.

It does nothing to the position of the transform, it returns a value. What you intend to do is apply a force. Which you can most easily achieve using a rigidbody on the force-receiving object, or by managing your own velocity vector in your player movement script.

To be clear, you mean if he doesn’t want to rely on OnTriggerEnter, I take it? You do need a Rigidbody if you want to use a trigger.

1 Like

My bad, i meant OP does not necessarily need to use rigidbody based movement and could instead apply his own “force” to his own velocity vector. Having something like that is a common approach on a lot of character controller designs, and controlling a player through actual physics can be tricky for most games. Which is why i wanted to mention it, but arguably worded it pretty horribly.

1 Like

hey guys,
thanks for your input…
actually I can´t use the rigidbody on my player because I am using the Character Controller on the Player…

(I tried it though, with no succesful result)

any idea how to achieve it without the rigidbody?

Use the Rigidbody and set isKinematic to true.

it doesn´t help… as I said the Player is controlled by the CharacterController … that´s why it doesn´t work with the Rigidbody…

I would need a solution without the rigidbody at all…

If you make the Rigidbody kinematic, you can use the CharacterController. The Rigidbody will no longer care about physics, but it will still cause OnTriggerEnter to be called when your character’s collider intersects the other collider.

If you want to use OnTriggerEnter, you are going to have to use a Rigidbody. Nothing else will generate a call to OnTriggerEnter.

1 Like

hey thanks again for your feedback…
I have added a rigidbody to the player and set it to kinematic but nothing happens… when the player enters the collider

any idea why?

Can you post your current code?

using UnityEngine;

namespace TheKit
{
    /// <summary>
    /// Use this to apply damage or kill player with triggers
    /// </summary>
    public class Kit_PlayerTriggerZone : MonoBehaviour
    {
        public bool BouncePad;
        [Tooltip("BouncePad?")]
        /// <summary>
      
        public float AmountOfForce = 20;

        private void OnTriggerEnter(Collider other)
        {
            Kit_PlayerBehaviour pb = other.transform.GetComponent<Kit_PlayerBehaviour>();
            if (pb)
            {
                //Check if its our
                if (pb.photonView.IsMine)
                {
                    if (BouncePad)
                    {
                       other.GetComponent<Rigidbody>().AddForce(Vector3.up * AmountOfForce);

                    }
            
               
                   }
             }
    }
}
}

Let’s put this between Line 17 and Line 18, run it again, and tell me if you get any output on the Console:

print("Trigger entered");

hi,
thanks a lot for your help! i really appreciate that…

I just inserted your line and yes I get the Trigger Entered in the console (check the image)

but i have used the trigger system already with other stuff (kill on enter for example) and it works just fine… the only thing that doesn´t work is the jump pad and I am struggling already for days…

Well, at least we know the trigger is entered. What does this say if you put it after if (BouncePad)?

print(AmountOfForce);

So it reads like this:

    if (BouncePad)
    {
        print(AmountOfForce);
        other.GetComponent<Rigidbody>().AddForce(Vector3.up * AmountOfForce);
    }
1 Like

hey it´s printing the amount of force (800)

Let’s see if we can at least make it do something, then. Replace this:

other.GetComponent<Rigidbody>().AddForce(Vector3.up * AmountOfForce);

with this:

other.transform.position = other.transform.position + Vector3.up;

Does that make the other object move upward?

I’ll just throw this in here: ForceMode.Force (the default) is for applying a force to a body. So it expects the force to be applied every physics cycle. For things like explosions or jumping, where we have one instance applying all the force at once, we would want to use ForceMode.Impulse. So even though 800 is a pretty large value, the force being applied this cycle may overall be too small to make a noticable difference.

other.GetComponent<Rigidbody>().AddForce(Vector3.up * AmountOfForce, ForceMode.Impulse);

yes, but just a second or less… than the player hits the ground again