Páginas

Mostrando las entradas con la etiqueta infection. Mostrar todas las entradas
Mostrando las entradas con la etiqueta infection. Mostrar todas las entradas

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


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