robothead

Flash and Unity development

Posts Tagged ‘Scripting’

Mouse platformer update: Simple 2d enemy movement in Unity 4

Posted by robotheadgames on September 5, 2014

Finally, before going in and tweaking the mouse platformer demo, adding my own art assets, etc., I wanted to get some basic enemy action going. Baddies who’d go back and forth and you could jump on and squish them. (Or whatever happens when you jump on your enemies.)

The example project has enemy spawners sending small hordes of them down through the platforms. I liked how this worked – it reminded me of old run-and-gunners like Gunstar Heroes when there seemed impossible numbers of baddies on screen but perhaps that was just clever game design. However, it seemed like the wrong approach for my game.

For now at least, I want the whole game to be about jumping. Shooting is fine but for this game perhaps it should be limited, like Mario’s fireballs, if even. I wanted enemies my hero would jump on or punch from below while jumping. (More on this in a bit.) I also wanted two classes of enemies for now – one that flew and another that stayed on the ground. Referencing my first blog post on this subject, Edward Engine had flying enemies and the Lerpz tutorial had ones that stood around in an idle state until you got too close and then they’d attack.

However, the ground based enemies I came up with are not like the Lerpz baddies. I may make a similar class to those later. Both my classes of enemies go back and forth, presumably keeping a vigilant eye on my hero and making life hard for him

Read the rest of this entry »

Posted in Game Design, Work in Progress | Tagged: , , , , , , , | Leave a Comment »

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…

Read the rest of this entry »

Posted in Game Design, Work in Progress | Tagged: , , , , , , , , | 2 Comments »

Simple One-Way Platforms in Unity 2D

Posted by robotheadgames on August 26, 2014

That’s right… 2D, not 3D…

I’ve been recently revisiting my mouse (the rodent, not the controller) platformer and I wanted to try out Unity’s relatively new 2D tools and see how they compared to Flash.

Note: I still like Flash, I’m quite comfortable with it as a 2D game dev tool and with AS3 but Unity has grown on me for game development.

Anyway, working from the 2D example project, all was well, except for one thing. One-way platforms. Again, you don’t get them out of the box. In 3D, as noted in the earlier post, this is easy enough to do by using a plane as a mesh collider. Unity could have made this easy in 2D by including the option of a one-way edge collider but they didn’t, edge colliders are two-way only. It seems to be a major oversight as one-way platforms are a major part of many old school 2D games. And they are an essential part of my mouse game. The entire game feels different without them.

There seems to be a good bit of demand for this feature and I found a number of solutions online. One, they have implemented a Physics2D.IgnoreCollision function in Unity 4.5 which seems to be most helpful. However, the simplest solution seems to be this one and it even works in Unity 4.3:

http://physicist3d.blogspot.com/2013/12/unity-tutorial-how-to-make-one-way.html

By Sudhir Attri. (Thanks dude!) Basically you make an empty GameObject as a child of your platform, give it a box collider that sits right below your platform and make it a trigger that turns the platform’s collider on and off. (Dead simple with their script.) That way your character can jump up through the platform and land on top of it. Success!

Except there is a problem. This only works once per game. Let’s say my mouse falls down from a higher platform and has to go back up. But he can’t, as the one-way platforms he’s passed through are no longer one-way and are blocking his way. This will not do.

Here is the solution I came up with. It’s simple: 

Read the rest of this entry »

Posted in Game Design, Work in Progress | Tagged: , , , , , , , , | 2 Comments »