robothead

Flash and Unity development

Simple Jump Pads and Wind Zones in Unity 2D plus Errata and Lerpz Tutorial Links…

Posted by robotheadgames on August 30, 2014

First, I goofed in my last post on the mouse platformer. The platform trigger should be set to this:

errata_triggerSettings

Oneway should be checked OFF. Why? You only want it enabled when it is triggered. Otherwise, when enemies come down from above, they will fall through all the platforms. Note: I’m using the enemy script from the 2D example, I am not sure what the enemies will do in my final game yet. Perhaps they won’t follow physics. It will be a learning experience.

Also, if you are looking for the Lerpz tutorials I mentioned in my first post, they are gone from Unity’s site. The PDF’s can be downloaded from here (2D) and here (3D). Assets for the 2D game (actually the whole 2D Unity project) are also on GitHub. 3D assets including scripts (which aren’t fully documented in the PDF) are in this project based on Lerpz 3D. They are also probably in this game also based on Lerpz (I haven’t checked.)

Next, how to make those jump pads and wind…

In my first mouse platformer post, the Flash Edward Engine example included both jump pads and wind. The Unity 3D example, based on Lerpz included jump pads (following the Lerpz 3D tutorial) and for the wind zone, I just sized one up vertically.

These 2D jump pads are inspired by that tutorial but are simpler, similar to the one way platform method I use. Jump pads can also be thought of as trampolines.

First make a new game object with its own sprite. (I just used the UFO base from the current 2D platformer example project because its the rough shape I want. Assign a 2D edge collider to it like this. 

Jump Pad

My edge is poorly drawn but its not final and it works.  (This also enables me to make slanty platforms. Yay.)

Then as before, add an empty Game Object as a child of the jump pad. (I named it JumpPadTrigger) Add a box collider to it (as a trigger) and position it at the top of the pad as shown. Attach this simple script (C#)

using UnityEngine;
using System.Collections;

public class JumpPadTrigger : MonoBehaviour {
public float jumpForce = 1200f;

// Use this for initialization
void Start () {
}

// Update is called once per frame
void Update () {

}

void OnTriggerEnter2D(Collider2D other){
other.rigidbody2D.AddForce(new Vector2 (0f, jumpForce));
}
}

}

and JavaScript:

#pragma strict
var jumpForce = 1200;

function Update () {

}

function OnTriggerEnter2D(other: Collider2D) {
other.rigidbody2D.AddForce(new Vector2 (0, jumpForce));
}

That’s it!

You can set Jump Force to whatever you like. Here it is the same value as the character’s regular jumps (1200). But as with the Edward Engine example, I’ve made two more jump pads higher up in the level that give him 2x and 3x jumps, just increasing Jump Force for each instance. Unity makes this really easy of course. And of course, the first jump pad gets saved as a prefab.

Note that the platforms can also be assigned a physics material that has bounciness. I have yet to try this but it may be interesting given the nature of this game.

As for wind zones, pretty much the same thing as jump pads. Use a different sprite in a new prefab based on the jump pad prefab, etc. I also added a particle system to give it that Sonic fan-blowing-dust/rubbish look, this may or may not make it into the final version. Then just make the trigger as tall as you want your wind zone to be but make its Jump Force really low. (I did 100.) This gave me the effect I wanted. If the character goes all the way up through the wind zone, he goes really high. But if he comes down upon it from above, it just buffets him up a bit.

Both problems solved. Also, I am enjoying Unity quite a bit and am thinking this example will be the basis for the final game.

One Response to “Simple Jump Pads and Wind Zones in Unity 2D plus Errata and Lerpz Tutorial Links…”

  1. […] Simple Jump Pads and Wind Zones in Unity 2D plus Errata and Lerpz Tutorial Links… […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: