Rabbit and the moon - Setting the traps

in #unity7 years ago (edited)

You may have seen me mention a couple of times that I'm very close to finishing a first platformer game and releasing it out in the wild for people to play, I'll even be putting it up on steam greenlight so it'd be really nice if people voted for me when the game comes out. However I've been wondering precisely because it's so close to finishing how much I should show you all so I decided I would show you one level since the game isn't that big or impressive, it's a very simple platformer but it took a lot of work to put together as It was pretty much a starter project to help me familiarise myself with the game engine.

Since I finally, with help got the saving and loading code working ( Yey! ) I can now focus on the actual gameplay within the platformer and work on the fun stuff like level design. In this topic I'm going to show you how I do traps, for programmers the premise is very simple a trigger collider that the player walks into which activates the trap, there was actually very little coding done to this, it was all physics. The only extra bit of code I have put in is for the sake of optimisation where the traps delete themselves after a certain number of seconds so that way we don't have constantly falling ice balls and floating asteroids everywhere that are being calculated off screen.

A bit of background on the game, as I said, my very first project, this is a simple platformer where you are a rabbit and your objective is to collect as many vegetables for points as you can and then get to the next level. You do this by reaching the moon, I based the setting off asian folklore.

https://en.wikipedia.org/wiki/Moon_rabbit

Here are some gifs as usual of me setting up one of the ice ball traps I have in the earlier levels so you can see more clearly what I'm doing, I don't want to give too much away, because otherwise you'll just be able to look at this blog and cheat your way through. I've been wondering about difficulty level also, I think if I get sales I have some patching software ready for the game and what I might do is if people find this game interesting i'll add much harder levels for free. Yes, that's right, no only will I be giving away free DLC content and not being a dick and charging you for it all, this game will be DRM free as well, in fact all games will, so if you want to can stick this on a USB drive and it will work from there if you copy it over. By the way I'll be doing this for all of my games in the future as well, it's not just a promotional thing.

https://gfycat.com/IllegalLoneImpala

https://gfycat.com/EssentialOrganicDarwinsfox

https://gfycat.com/WastefulImmaterialIberianlynx - This is the gif where I show it actually working, the gameobject activates itself when you cross an invisible point and the ice ball will try to kill you.

Setting up traps like this is really simple by the way, all you need to do is make sure the trap you have set up is deactivated because any animations and physics will of course automatically play out if you haven't coded it to go off at a certain time. I may however because of my new saving and loading code have to adjust things a little bit but if you don't care about that sort of thing you can just use the simpler version.

Here's the code I used to make this.


using UnityEngine;
using System.Collections;

public class ActivatePhysicsTrap : MonoBehaviour {

    public GameObject trapObject;
    public float DestroyTrapCountDown;

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {


    
    }

    void OnTriggerEnter2D (Collider2D other)

    {
        trapObject.SetActive (true);
        Destroy (trapObject, DestroyTrapCountDown);
    }

}

Bah, can anyone link me a tutorial or something on how to format this post properly for code? Would appreciate it.

Sort:  

The game looks pretty interesting! As for the code styling, you can add 4 consecutive ~ signs to start the block and 4 ~ to end it. This is when you are in a markdown, not editor mode.

Aha! Thank you, that works perfectly and thanks for the comment, I drew all the art myself.

Coin Marketplace

STEEM 0.31
TRX 0.12
JST 0.033
BTC 64341.19
ETH 3145.13
USDT 1.00
SBD 4.00