Jump Pad Example

BrandSpankingNewBrandSpankingNew Posts: 2,362Member, MPTester
I found myself unable to do any useful work today, so I decided to mess around with a jump pad scheme.

If any of you are interested in something like this, after you have watched my tacky video, then just leave a comment and I will clean up the two simple scripts that I made and post them here for you.

You'll have to fight your way through getting your prefabs set up, inventory set up, etc., but I'll be happy to paste in the scripts.

I suggest viewing this in full screen mode. It doesn't look real good regardless, but it is less terrible in full screen. :-)

https://youtu.be/p8HYpDJb_AA
Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
Democritus

Comments

  • JustinJustin Posts: 356Member, Administrator, Moderator
    When I try to view the video it says "This video is unavailable"

    [ UFPS Docs ] . . . [ F.A.Q. ] . . . [ Tutorials ] . . . [ Knowledgebase ]
    [ Games Showcase ] . . . [ Get it now! ]

    [home] [twitter] [youtube]
  • BrandSpankingNewBrandSpankingNew Posts: 2,362Member, MPTester
    @Justin , thanks for the heads-up! Some simpleton, the author, had accidentally marked the awful video as private, rather than simply unlisted. It is all set for viewing now. (Given the quality, it would probably have been considered a public service if you hadn't mentioned it to me! lol!)
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
  • RoyalAllenRoyalAllen Posts: 219Member
    @BrandSpankingNew this is really cool.! I like the level too..gives a sense of a living world.
    http://brayboygames.weebly.com
    "It's all about being creative."
  • BrandSpankingNewBrandSpankingNew Posts: 2,362Member, MPTester
    @RoyalAllen ... Well, thank you for saying that. You'll recognize that the first scene in that video is really the "outdoors" part of Demo Scene 1 where the gigantic red exploding cubes are located.

    I use that scene as my test area (when I am not doing bad things to a copy of Demo Scene 3) and I just keep expanding the walled-in area as real estate requirements demand. In fact, all of those switches on that big black teleport panel lead to additional test areas. I never really throw away a scene, even if it is just awful. I'm a hoarder and it is too easy to add another button and a label to my switch panel prefab.

    The second scene in the video is just a copy of Demo Scene 2 with a little forest and some rocks and first aid kits thrown in. Oh, and rain. I find it soothing.

    In these demo-video builds I turn off all of the helicopter's weapons and the sentry guns and bots (they are just brutal and it is very annoying to run for your life and try to do a demo at the same time), but you might notice that the helo's still shine their spotlights upon the player whenever they are within range.

    I have to say, in my own defense, that the deployable jump pads actually work much better than that video shows. A keen eye will notice a couple of places where the player takes fall-damage, but those were "operator error" situations. Once the player has launched, anything that can be construed as him being "grounded" (such as briefly touching the railing around the top of my storage shed in that first scene) will immediately turn the damage back on, and if his velocity or height above his final landing spot is too great, then pain occurs. I think that's fair though. Clumsiness should be punished! lol!

    I'm sure that everyone likes my pink grenades! ha!
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
  • danuixas Posts: 4Member
    Hello is this still avaible and possible to obtain ?
  • BrandSpankingNewBrandSpankingNew Posts: 2,362Member, MPTester
    @danuixas , Sure it is. I will be happy to provide the scripts and some notes about preparation. It might not be until tomorrow before I can get that stuff pasted in here, so please be patient. I'll also make a new (quick and dirty) video that might be helpful. I did not, as I had wished to do, continue working upon this little gadget but I have made some improvements, compared to what is shown in that original video. It has been months since I last looked at these things so give me a few minutes to figure out what I was thinking. Ha!
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
  • danuixas Posts: 4Member

    @danuixas , Sure it is. I will be happy to provide the scripts and some notes about preparation. It might not be until tomorrow before I can get that stuff pasted in here, so please be patient. I'll also make a new (quick and dirty) video that might be helpful. I did not, as I had wished to do, continue working upon this little gadget but I have made some improvements, compared to what is shown in that original video. It has been months since I last looked at these things so give me a few minutes to figure out what I was thinking. Ha!

    Okay, thanks alot !
  • BrandSpankingNewBrandSpankingNew Posts: 2,362Member, MPTester
    edited January 5
    In the interest of entertainment, I have prepared another JumpPad video!
    You will notice that there is a jumppad present in the scene, observe
    it's appearance and it's characteristics. There are also jumppad
    pickups in the scene and you'll see how they compare to an actual
    grenade. Sorry the video is a little long, but I had trouble getting
    some of my props into position. lol! The video quality is not great,
    and it was shot in the editor, but maybe you'll glean something
    from it.

    https://youtu.be/OAfSEqNDH40

    I don't know how much text will fit into a single comment window,
    so I may have to extend this to an additional comment.... 'cause
    I love to blab.


    Before you begin I should explain a couple of things about what in the
    world I was thinking about when I did this little thing months ago.

    I wanted a JumpPad and I wanted to be able to move the pad around at
    runtime to suit the circumstances found in a scene. I began by making the
    pads square and making them grab-able (using vp_Grab, just like a crate)
    and I set them up so that they wouldn't launch me until I had placed them
    and enabled the launching circuits via a button on the pad (I did that
    by using the very handy vp_Switch).

    That quickly got to be a little tedious because of the placement of
    colliders and triggers and stuff, and it wasn't really handy to have to
    be running all over the place to grab another JumpPad and bring it to
    a new location.

    So, at that point I decided to treat my jump pads as consumable inventory items,
    just like a grenade. I got to keep the functionality of moving the pads
    after deployment, without the hassle of having to flip a switch to make them work
    and if I was a smart player then I would always have a few jumppads with me.

    I encourage you to begin this little exercise by mastering the process
    of duplicating all of the characteristics of the existing grenade pickup
    if you intend to use this little sample as anything more than just a grin.

    I mean, make something behave exactly like a grenade pickup, but have it
    not be a grenade! It must be able to be picked up, stored in inventory,
    thrown, and provide some kind of effect upon detonation. I am not going
    to attempt to talk you through all of that. That's the hard stuff. What
    I am giving you here is the easy stuff. :-)

    You will see that when a grenade explodes that it's damage handler
    spawns effects. Those effects can be anything. In the case of this
    JumpPad sample, the effect used when my "pink grenade" detonates
    is the JumpPad prefab (that I will explain below) and a little smoke.

    The JumpPad is a prefab that knows how to launch a player, and it
    is also able to be moved around in the scene after it has been
    deployed (thrown like a grenade) by the player. It is a totally
    separate thing from the JumpPad pickup item, just as a grenade pickup is
    a totally separate thing from the grenade that a player tosses.

    You can certainly just drop jumppads around in your scene, if you wish,
    and never go to the trouble of making them thrown pickup items.

    In my sample I have built the hierarchy of the prefab thus:


    > JumpPad -- This is a parent object. It contains the following ...
    Transform
    Cylinder(Mesh Filter) -- this is the round, flat, pink part.
    Mesh Renderer -- apply any ugly material here.
    Rigidbody
    Box Collider -- not a trigger!
    Vp_Grab (Script) -- modified to suit my purposes, I will explain.
    BSN_Rotate Jump Pad (Script) -- I will explain.
    Shader

    The JumpPad has a child object.

    > Launcher -- This is where the jumping work gets done.
    Transform
    Cylinder(Mesh Filter) -- this is the round, flat, shinny part.
    Mesh Renderer -- apply any fun material here.
    BSN_Jump Pad Trigger (Script) -- I will explain.
    Capsule Collider -- Is Trigger set to True.
    Audio Source -- to play a whoosh!
    Shader

    The Launcher has a child object.

    TextMeshPro - Prefab 2 -- this is the component that displays
    the "^" symbols that I used in this
    sample to indicate the number of jumps
    that a pad contains.
    It is beyond the scope of this sample
    to attempt to tell you how to use
    TextMeshPro. You may wish to display
    your jump count in some other manner
    or perhaps not at all. I used it
    only as an exercise in bending it
    to my will and to learn the components
    in the process. It's fun stuff.
    TextMeshPro is a free Unity asset store
    asset that they aquired not too long ago.



    Okay, so because I mentioned above that I had modified vp_Grab,
    I feel compelled to talk about modifying base code. I typically, religiously, avoid
    doing that kind of thing. It's tacky. But in this case I did, because
    I needed to expose a boolean value contained in the vp_Grab script. And
    because I was being lazy and because I am seriously anal about keeping
    track of any changes that I make to any product code so that I can easily
    duplicate my various misadventures when a new version of anything is released.
    I am also backupaholic too, and besides, I only make very small, non-lethal
    changes to base code. Typically, if it needs more than one line, then it
    is time to extend. You can proceed as your feelings dictate.

    The change that I made to vp_Grab is as follows:


    // BSN changed this!!
    //protected bool m_IsGrabbed = false;
    [HideInInspector]
    public bool m_IsGrabbed = false;



    We will be using our access to that bool later on in order to let our Luncher
    know that we don't want to be launched at this particular time.

    The other script upon the JumpPad parent object is a simple convenience item.
    It orients the jumppad after the thrown JumpPad grenade thing explodes.


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

    public class BSN_RotateJumpPad : MonoBehaviour
    {

    // this script rotates the instantiated jumppad into it's "proper" rotation

    void OnEnable ()
    {

    this.transform.rotation = Quaternion.Euler(0,0,0);
    }

    }



    Let's continue this in another comment window! See below ...

    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
  • BrandSpankingNewBrandSpankingNew Posts: 2,362Member, MPTester
    This is a continuation of the comment above ...


    Okay, so now we are ready to look at the script that is on the Launcher,
    that child of the JumpPad. It is really pretty straight forward, and again,
    you don't have to mess with the TextMeshPro stuff if you don't wish to.


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using TMPro; // you don't have to use this free Unity TextMesh Pro stuff


    [RequireComponent (typeof(AudioSource))] // you don't have to make sounds if you don't want to

    public class BSN_JumpPadTrigger : MonoBehaviour
    {
    private bool activatedThePad; // true at OnTriggerEnter, false on conditional in LateUpdate
    private bool playerHasJumped; // true on conditional in lateUpdate, false on conditional in Update
    private Transform thePlayer; // set at OnTriggerEnter, used to measure player altitude
    private Vector3 goToHeight = new Vector3(0,0,0); // I'm only using Y, but you could do more things.
    private Vector3 addForce = new Vector3(0,0,0);
    private int jumpCount; // set at OnTriggerExit. counts how many times has this pad been used
    private vp_Grab grabScript = null; // monitor pad grabbing and moving
    private bool parentGrabbed; // true if grabbed, otherwise false
    private TMP_Text displayText; // TextMeshPro stuff. display text above jump pad
    private RectTransform rotateDisplayToCamera; // TextMeshPro stuff
    private float destroyPadDelay; // used to count time
    private AudioSource newAudio; // if you want sound then you need this

    // the following are adjusted once, upon the pad prefab, so that all instances behave the same
    public float howHighToJump = 5.0f; // set point for max altitude
    public float howMuchForce = 0.05f; // use small amounts, mostly. experiment! lol!
    public int howManyJumps; // how many jumps allowed per pad
    public Transform lastJumpEffect; // an optional effect prefab
    public AudioClip theWhoosh; // sound file to use if you want sounds

    void Awake()
    {
    grabScript = GetComponentInParent<vp_Grab>(); // this takes us to our vp_Grab modification!
    jumpCount = 0;
    activatedThePad = false;
    playerHasJumped = false;
    parentGrabbed = false;
    displayText = GetComponentInChildren<TMP_Text>(); // TextMeshPro stuff
    rotateDisplayToCamera = GetComponentInChildren<RectTransform>(); // TextMeshPro stuff
    }



    void Start()
    {
    newAudio = GetComponent<AudioSource>();

    newAudio.clip = theWhoosh;

    addForce.y = howMuchForce;

    MakeMarks();
    }

    // TextMeshPro stuff
    // display some text to indicate max number of jumps.
    // this also removes text in a top-down manner.

    void MakeMarks()
    {
    // don't do any loops that don't serve a purpose
    if (howManyJumps == jumpCount)
    {
    displayText.text = "";
    return;
    }

    // this section is here to make my "^" marks disappear in a top-down way.
    // when the display first appears it will look like this, because I'm doing 3 jumps per pad

    // ^
    // ^
    // ^

    // Then after the first jump it will look like this

    //
    // ^
    // ^

    // After the second jump it will look like this

    //
    //
    // ^

    // The marks disappear from the top of the list downward.



    // make an empty string each time this routine is called

    string temp = "";

    // if N is less than the current jumpcount
    // then add a blank line to temp.
    // Initially N will be equal to jumpCount, not less than,
    // so this loop won't do anything at Start

    for (int n = 0; n < jumpCount; n++)
    {
    temp = temp + " \n" ;
    }

    // if howManyJumps minus the jumpCount is less than i then append a mark "^" to temp.
    // At Start, since jumpcount will be zero, we add the amount of marks found in howManyJumps
    // until i reaches that count.



    for (int i = 0; i < (howManyJumps - jumpCount); i++)
    {
    temp = temp + "^\n" ;
    displayText.text = temp;
    }
    }

    void OnTriggerEnter(Collider col)
    {
    // If we are grabbing the jump pad, then do nothing.
    // It is possible that a player might come into contact with the trigger after the grab begins.

    // Use care when positioning and sizing your trigger collider or your player might get launched
    // while attempting to grab the device.

    if (grabScript.m_IsGrabbed) return; // this is why we modified vp_Grab!

    // only launch players

    if (col.gameObject.tag == "Player")
    {

    thePlayer = col.gameObject.transform;

    goToHeight.y = vp_LocalPlayer.Ground.transform.position.y + howHighToJump;

    activatedThePad = true;

    if (newAudio.clip != null)
    {
    newAudio.Play();
    }


    // only count player jumps
    jumpCount = jumpCount + 1;

    // we've jumped, so adjust the display
    MakeMarks();

    }
    }



    void Update()
    {
    // don't bother with update if we are moving the pad

    if (grabScript.m_IsGrabbed) return; // this is why we modified vp_Grab!

    // TextMeshPro stuff. just rotate the text display constantly

    rotateDisplayToCamera.transform.Rotate( Vector3.up);


    // don't hurt the player with fall damage if the player has entered the trigger

    if (activatedThePad)
    {
    vp_LocalPlayer.DamageHandler.AllowFallDamage = false;
    }

    // has the player been launched?

    if (playerHasJumped)
    {
    // if the player has landed, then the player is not pad jumping and we are allowed to
    // hurt the player with fall damage again.
    // Being grounded can mean a lot of things. So, don't touch anything while in mid-air!

    if (vp_LocalPlayer.IsGrounded)
    {
    playerHasJumped = false;

    vp_LocalPlayer.DamageHandler.AllowFallDamage = true;

    if (jumpCount == howManyJumps)
    {
    StartCoroutine("DelayedDestruction");
    }
    else
    {
    // a little error trap, because I am paranoid

    if (jumpCount > howManyJumps)
    {
    jumpCount = howManyJumps;
    }
    }

    }
    }

    }

    // we don't really want to destroy the jump pad
    // before the player has a chance to land his last jump
    // and watch the pad blow up.

    IEnumerator DelayedDestruction()
    {
    destroyPadDelay = 0;

    while (destroyPadDelay < 20.0f) // adjust to suit or make a public variable
    {
    destroyPadDelay =+ destroyPadDelay + Time.deltaTime;
    yield return new WaitForEndOfFrame();
    }

    // if we want the jumppad to just disappear, then skip
    // putting the effect onto the device and just destroy it.

    if (lastJumpEffect != null)
    {
    Instantiate(lastJumpEffect, transform.position, transform.rotation);
    }

    Destroy(transform.parent.gameObject);

    }

    void LateUpdate()
    {

    if (activatedThePad)
    {
    // if the player has not reached the height set point,
    // then add some "y" force to the player.
    // Using large values in howMuchForce will make the player
    // blow right past the height set point, and it happens really fast! (a feature?)

    if (thePlayer.transform.position.y < goToHeight.y)
    {

    vp_LocalPlayer.AddForce( addForce);

    playerHasJumped = true;

    }
    // if the player has reached or exceeded the height set point,
    // then reset our knowledge of the trigger's state

    else
    {
    activatedThePad = false;
    }
    }

    }

    }



    So, there ya' go. Good luck with your game.
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
  • danuixas Posts: 4Member
    Wow, thanks alot mate, that actually helped me to solve one problem that i had with a custom ufps weapon i was making too, i appreciate your effort to explain this so clearly alot ! :)
  • Zrexa Posts: 97Member
    @BrandSpankingNew Thanks, it was interesting to see how you did this.
  • BrandSpankingNewBrandSpankingNew Posts: 2,362Member, MPTester
    It is truly a pleasure to be of service. You are very welcome. There must certainly be better ways of doing what I have provided here, so don't take this thing as a solution ... but rather as a jumping off point for your own attempts. Don't forget to make your game fun, huh?! That's the key!
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
  • danuixas Posts: 4Member

    It is truly a pleasure to be of service. You are very welcome. There must certainly be better ways of doing what I have provided here, so don't take this thing as a solution ... but rather as a jumping off point for your own attempts. Don't forget to make your game fun, huh?! That's the key!

    Yes fun is the key of gaming, sadly alot of indies these days loves to forget it :(
  • TryThisTryThis Posts: 974Member
    edited January 10
    Yeah, yeah, same ol' boring jumppad stuff, over and over! I could have jumped into that balloon without all of the theatrics!

    (Hey, bud!, you know that this was supposed to be a funny!)
  • BrandSpankingNewBrandSpankingNew Posts: 2,362Member, MPTester
    Ahh! A comedian! yuk, yuk! ha!!! (please, show me your video of you jumping into the balloon!)
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
Sign In or Register to comment.