Páginas

Unity3d Radar script

I was looking for a way to make a radar or minimap in Unity3d but not adding other camara, just a square and some dots inside representing my game objects. 

I found someone who needed the same as I (http://answers.unity3d.com/questions/62018/how-to-make-a-radarmap.html). I took the Justin's Zaun radar script from the Unity wiki because it's easy to use and is customizable. You can show up to 4 kinds of objects on the radar but it would be easy to add more blip types.

Here is the result, just what I need


Script and Usage Instructions

Attach this wherever you like, I recommend you attach it where the rest of your GUI is. Once attached take a look at the inspector for the object. You are going to see a bunch of options to setup. I've tried to give a set of defaults that will work with little messing around.

The first item that should be set is the "Radar Center Tag" for anything of interesting to happen. This tag should be the object at the center of the radar, typically this is the local player's object. Place a check in the "Radar Center Active" box to diplay the play on the radar.

The second item that should be set is the "Radar Blip1 Tag." This is the tag given to the objects you want to show on the radar. Typically this would be the remote player's tag or the bad guy's tag.

To turn on the display of the blip place a check in the "Radar Blip1 Active" box.

If you run your game at this point you will see a radar in the bottom center of your screen that is showing you all the remote players/bad guys that are around you.

Now that you have seen a quick example of the radar I'll explain all the options. There looks like a lot but they are split into two sections. At the top are general radar settings that determin how you would like the radar to look. On the bottom there are settings for the blips

I'll explain the blips first. This radar supports up to 4 types of blips. Each blip has an "Radar Blip# Active" option for turning on or off the blip. This allows you to have everything setup and then in game based on events to turn on the display of different types on blips.

The second options is the "Radar Blip# Color" setting. This is the color of the blip. Not hard to explain, it changed the color of the object's blips for a given Tag. The last option for a blip is "Radar Blip# Tag." This is the tag for the object you would like to have on the radar.

Some examples would be using Blip1 for bad guys, Blip2 for items the play is trying to find, Blip3 for forts and Blip4 could be the level's exits. Having the items on the radar in differnt colors will let the player identify the type of object the blip represents.

The top options are the overall settings. First is the location of the radar. There are several options to choose from. If you choose "Custom" you have to fill in the "Radar Location Custom" to define the location. When you are defining the location please note this is the center of the radar.

The third option "Radar Type" is how you would like your radar to look. You have a choice of Textured, Round and Transparent. The default is Round and is the colored bullseye you saw at the start if you played with the first example. If you choose Textured you MUST set "Radar Texture" to some image for the background. If you choose Round you can change the colors used in the bullseye with "Radar BackroundA" and "Radar BackgroundB"

The last two options are about the size and zoom of the radar. The "Radar Size" is a percent of the screen the radar will take up, for example .2 is 20% of the screen. The "Radar Zoom" determines how much of the map should be displayed on the radar. Making this number smaller will zoom out and show you more stuff.

Get the script from https://gist.github.com/vackup/7715805 

Unity Ragdoll and Collisions with Rigidbodies with Kinematics

In my last post http://vackup.blogspot.com.ar/2013/11/unity3d-kill-character-and-make-him-die.html I wrote how kill a character (that uses a rigidbody) and make him die like a ragdoll. The solution was simple, just add him a ragdoll with Unity Ragdoll wizard and set all rigidbodies as Kinematic.

This was working great but all characters don't collide and they pass through other objects. Ouch!!

Searching the internet, I found that "If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore.http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-isKinematic.html

Also I found that someone had the same problem I have "I can't seem to find a specific answer for this. Mainly, I have an enemy rigidbody in my game who, when hit by an attack of some large value, goes ragdoll (isKinematic = false). However, when he is chasing the Player with isKinematic = true, he phases through terrain and such. Is there an elegant way of having an enemy be allowed to go into ragdoll and still collide with the environment?http://answers.unity3d.com/questions/167712/collisions-with-rigidbodies-with-kinematics.html

And the reply was something I don't want to hear "Actually the only two components that can detect collisions are: the CharacterController and a non-kinematic RigidBody without any exceptions (afaik). However the CharacterController uses it's own detection method and is not really part of the physics system.

The only difference between a simple GameObject with a collider and one with a kinematic Rigidbody attached is that the kinematic Rigidbody can wake up other non-kinematic Rigidbodies. Non-kinematic Rigidbodies fall asleep after a few seconds. They can only detect collisions when they are awake. If you move a GameObject with a sleeping Rigidbody it will wake up automatically, no matter what method of movement you're using (transform.position, AddForce, MovePosition).

The only use of a kinematic Rigidbody is that when you move it into a sleeping Rigidbody it will wake up and would perform the collision check. Keep in mind that the collision messages are sent to both objects but only a non-kinematic Rigidbody can produce them.

I'm not sure how your ragdoll-setup looks like, usually you have multiple body parts that are connected with joints. To move the enemy while he's alive you should use either a CharacterController, or a non kinematic Rigidbody. You should remove it when you turn it into a ragdoll.

If you use a Rigidbody you can set freezeRotation to true so the Rigidbody is not rotated by the physics system but you're still able to rotate the object via script. You can also use Rigidbody.constraints to prevent the rotation and / or position change caused by the physics system."

So I started to think what can I do ... I thought that if isKinematic wasn't my solution, it would be great if I could create the ragdoll at runtime using a script.

So I searched the internet and found someone asking how to "Export ragdoll setup to script" (http://answers.unity3d.com/questions/188917/export-ragdoll-setup-to-script.html). The reply was "I created a code generator for C# and released it as open source under MIT license. Further on I wrote an article in my blog where you can find the code as well". He was talking about C# Code Generator As Add-on for Unity3D Ragdoll Wizard

There you can find the code to download and how to use it. I use it in my project and the result is what I was trying to achieve. The results are here: http://bit.ly/1beCGTg


Unity3d: kill a character and make him die like a ragdoll

The other day, I shown a friend of Rosario Game Dev the lastest version of my game where I introduced bombs and explosion. He told me it would be great that when a bomb explodes, characters fly over the scene and that I could achive that by using a ragdoll. You can see a proof of concept here http://bit.ly/17pl47F

So, what's a ragdoll? A ragdoll "is a children's toy. It is a cloth figure, a doll traditionally home-made from (and stuffed with) spare scraps of material" and the same approach is used in video games.

Unity has a simple wizard that lets you quickly create your own ragdoll. You simply have to drag the different limbs on the respective properties in the wizard. Then select create and Unity will automatically generate all Colliders, Rigidbodies and Joints that make up the Ragdoll for you. (something you need to know / guess, as a ragdoll is basically a collection of rigibodies it will be affected by physics, gravity and forces)

Here you have a Unity 3D Ragdoll Easy Tutorial (this all you need to know to make a ragdoll)


This is really easy, but what if the character have any other logic or components like animators, rigidbody, script, etc?

Let's take a look at Ethan from Unity3d Project #01: Stealth. Ethan has a lot of components attached to him.


If I just add the ragdoll to Ethan, It'll be a completly mess (I've already did it, try it by yourself), so what can we do? These are the step I follow (guided by some answers I found on the Internet):
  1. Create a ragdoll to Ethan
  2. Disable all child (ragdoll) rigidbodies (script AnimatorToRagdoll.cs)
  3. When Ethan dies, destroy / disable main components (With a mouse click, Ethan dies)
  4. Eneable all child (ragdoll) rigidbodies 

The result is here http://bit.ly/17pl47F  With a mouse click, Ethan dies

You can download the full project here: http://bit.ly/1dYsO1I


Epidemic: using a resource pool system

One of the biggest problem in game development and specially in mobile game development is memory allocating and deallocating. Some OS like iOs let you take the memory you need but doesn't like the idea allocating and deallocating continuously and makes your app or game to crash.

Always a profiler (eg: Unity Profiler) is needed to see how your game do its job under the hood.

A bad practise is Instanciating and Destroy objects because they are expensive task, they do a lot of memory allocating and deallocating, generates garbage (that the garbage collector needs to collect).

So what can we do if we need to Spawn and Despwn objects in our game? The solution is the use of some kind of resources pooling.... This mean, load everything you can / need when you game is starting - instanciate objects - and mark then as Inactive. When you need one object, just look for one Inactive object in your pool, mark it as Active and use it. When you don't need anymore, mark it as Inactive. That's all.

In the case of my game, I just start using resources pools for bombs and explosions because at this moment, they are the only objects that Spawn and Despawn.

I was looking for a free, open source and easy to install / use resources pool and the solution was Prefactory_v1_0, a simple object pool manager for Unity3d. Just visit Prefactory_v1_0 web site to download it and for instructions how to use it.

I just want to thanks Boon Cotter for his excelent Pool Manager and for sharing it!

Remember, here http://bit.ly/1beCGTg you can see a live version of my game. Also, there is a new dead sound! Enjoy it

Epidemic update, bomb and explosions

Detonator Explosion Framework for Unity makes incorporating good explosions easier for all types of developers. At its most basic level, Detonator is a component that can be attached to any GameObject. At runtime it then creates an explosion with configurable color, size, duration, detail, and sub-elements like sparks, smoke, and shockwaves. The Detonator Parametric Explosion Framework has been developed by Ben Throop for the Unity Summer of Code 2009.

You can play with a running example of Detonator here: http://variancetheory.com/detonator/

Thanks to Detonator, I could include astonishing explosions in a really easy way.



Just add a component script to my bomb object (eg: a sphere). My script has a public gameobject variable so I can assing the explision prefab I like most.


And only in my script, I just wrote code for OnCollisionEnter:

 void OnCollisionEnter(Collision collision)   
 {  
       // Instantiate a detonator game object where the bomb is  
       Instantiate (this.detonator, this.transform.position, Quaternion.identity);  
       // Destroy the bomb (because it exploded lol)  
       Destroy(this.gameObject);  
 }  

Remember, you can take a look at the last version of the prototype here http://bit.ly/1beCGTg

Of course, there are a lot of things to improve but I'm just starting

Epidemic, my new "work in progress" game prototype

Inpired by Zombie Infection Simulation v2.3 - The Original and the movie Contagion, I decided to start developing a game prototype using Unity3d

My game should answer some of these questions (in a funny and challenging way):
  1. How long does it takes to the infection to spread?
  2. What are you going to do to save the not infected humans?
  3. How will they react?
Take into account that you'll only have limited resources, so live or die, make your choice

I don't know how this prototype will end but I'm just starting to develop it (also starting to learn Unity :)

Up to date, I only have a bunch of human running, some are infected and some are not infected. I have a few rules already implemented:
  1. When an infected one "touch" a not infected one, it infect him
  2. The infected ones walk slower the the not infected ones.
  3. An infected human dies some second after have been infected.
  4. With a Mouse click you can "fire" bombs that can kill humans (infected and not infected humans)
Also there are some rules to be implemented, for example:
  1. A not infected human can live some time without food
You can take a look at the last version of the prototype here http://bit.ly/1beCGTg

If you any idea or feedback, don't hesitate in contect me.

NOTE: some models were taken from Stealth Unity Tutorial just for prototyping purpose