"Deathzone" script

I have a marble game and would like to have a deathzone added to the game where when you fall off you hit the invisible zone and respawn at your last checkpoint.

I’ve look all over for scripts but they all involved character controllers, if you add a controller to a marble it just makes it rotate all in directions over and over.

Another script i’m looking for is a better marble script to the one i have, the one i have doesn’t seem to have proper “y” gravity, so when rolling down slopes it doesn’t move very quickly unless you push a directional key.

Any help is much appreciated :slight_smile:

Edit - The first picture is the view when i hit the play button the second picture is the layout of my scene, hopefully these will help in understanding my problem.


Well, the killzone itself is easy. In OnTriggerEnter (the collider should be a Trigger), just check if the collided object is the player marble.

The killing and respawning, however, is something different and I couldn’t answer without better knowledge of your game’s structure and your plans.

If I make a few assumptions about your code, I’d program the trigger code in DallonF’s idea like this:

var go_next_spawn_point : GameObject;

private var v3_next_spawn_point : Vector3;

function Start() {
    v3_next_spawn_point = go_next_spawn_point.transform.position;
}

function OnTriggerEnter(other : Collider) {
    var go_marble : GameObject;
    go_marble = other.gameObject;
    go_marble.transform.position = v3_next_spawn_point;
}

You attach this code to the trigger at each “teleportation starting point”. In the Inspector variable go_next_spawn_point, you drag the trigger that’s located at the next spawn point (the “teleportation ending point”).

This code is

  1. off the top of my head
  2. hasn’t been tested
  3. most likely will need to be tweaked

And on respawn you probably want to reset the velocity.

The script you’ve provided works more like a teleporter but i’ve still managed to make use of it by using invisible barriers so when you fall off the platform it kind of looks like a death and respawn system, so thank you for the help :slight_smile: