OnTriggerEnter, Push player into the air.

Hello Unity Community,

I am trying to develop a script that uses the OnTriggerEnter function. When the player walks into a trigger, they must be pushed up into the air. It sounds like a simple program but for some reason, I just cant get it working. If someone knows how this is done please reply because I am lost!

-Thanks.

BUMP…

Still lost on how to achieve this effect. The part I am confused on is, when the player walks into the trigger, what should I use to make the player launch up into the air?

Using Move? Its reference page contains an example of jump.

You should attach that script to the box (and set “Is Trigger” to “true” ), then add onto the scene “First Person Controller” and set it’s tag to “Player”.

    CharacterController controller;
    GameObject player;

    Vector3 some;

    void Awake()
    {
        player = GameObject.FindGameObjectWithTag("Player");
        controller = player.GetComponent<CharacterController>();
    }

    void OnTriggerEnter()
    {
        some = new Vector3(player.transform.position.x, player.transform.position.y + 1200, player.transform.position.z);
        controller.Move(some * Time.deltaTime);
    }

Thanks for the replies, I have tried the things you suggested but nothing is working, any other ideas?

Um, you want OnTriggerStay, not Enter. This way, the character walks in stays a while. He receives a controller.Move(Vector3.up * upSpeed); The longer he stays the more he receives the up movement.

I dont want the player to continue to move up, just bounce into the air. This is what I have so far, which does not work!

var upSpeed : float = 10;
var thePlayer : GameObject;

function OnTriggerEnter () {

    thePlayer.Move(Vector3.up * upSpeed);
}

Check the value of upSpeed in the unity editor is it 10?
The Player must also had a rigidbody for in order for the trigger to work

very simple but you must adjust this code bit more the be more effective IE. if you still stay inside trigger it counts , when you leave it disables. I havent tested this but this is how it should work

Hope it helps.

var upSpeed : float = 10;
var thePlayer : GameObject;
var timer1;
var StartTimer : boolean = false;
function OnTriggerEnter () {
timer1 = 0
StartTimer = true;
Main();
}

function OnTriggerExit () {
timer1 = 0
StartTimer = false;
}

function Main(){
while (Timer1 < 100) {
    thePlayer.Move(Vector3.up * upSpeed);
    timer1++;
  }
}

Thanks Purri,

Script had a couple errors, I fixed them.

I get this error though,

Assets/Scripts/JumpPad.js(18,15): BCE0019: 'Move' is not a member of 'UnityEngine.GameObject'.

use something else like transform.

var upSpeed : float = 10;
var thePlayer : GameObject;
var timer1;
var StartTimer : boolean = false;
function OnTriggerEnter () {
timer1 = 0
StartTimer = true;
Main();
}

function OnTriggerExit () {
timer1 = 0
StartTimer = false;
}

function Main(){
while (Timer1 < 100) {
    thePlayer.Transform(Vector3.up * upSpeed);
    timer1++;
  }
}

Transform did not work, it had the same error. Any other ideas? :slight_smile: