Robots and Ragdolls

I’ve taken a break from my full game to work on a side project – creating a robot character from scratch, based on a friends concept art design, seen just here. This was created by the massively talented James Wetherell (also known as ‘Wev Art’), who’s fine work can be seen HERE.

Image

The web player for this is here

A higher quality version is available for download on PC and also on Mac:

PC here

OSX here

The chosen robot was the central character. I have it in mind to create a robot centric FPS style game, but for now wanted to simply create a high quality robot character that could work with Unity. I would be using 3DS Max, ZBrush for modelling, and XNormal and Photoshop for texture work.

My previous character (the Red Panda) worked out very nicely, but I had made mistakes along the way and also learned a great deal from tutorials and I wanted to follow all the correct steps to create the character properly. The first step in this was creating a base mesh in 3DS to use in ZBrush. The arm was to be mirrored, so is missing (the weapon was to be made, but later abandoned as it was not going to be used in any way):

Image

The main goal here was to follow the forms of the design to create an accurate base from which to model in ZBrush. Note the numerous triangles – not ideal! Keeping your ‘loops’ clean is important and I would discover as I progressed that I had basically screwed this up.

This step took a good few days, using Edit Poly mostly to extend my mesh and model. Really I should have gone further with it to make smoother shapes and more detailed work, but I stuck to a low poly focus. Considering I would end up retopologizing this later it was a pretty pointless effort and I should have just gone as high poly as possible in order to make it more accurate.

Next step was to build on this Model with ZBrush:

Image

Image

You can see in the above two stills the detail I was able to go into and I’m pretty happy with how well it matched the original design. I especially love the main form that spreads from the shoulders down the sides and to the outer thigh.

Image

The body has quite a human, curved design, while the arms and head have a more angular form. In retrospect my model lost some of the subtleties of the original concept, but I feel it’s important to finish what you begin and so completing the model was more important that scrapping it at any one stage to start again.

With the high poly model completed I needed to create a low-poly Unity compatible model.  ZBrush has it’s own retopologisation tool called ‘ZRemesher’ which automatically creates a low poly model (with options to tune), saving me time with the main body:

Image

This is still way too high poly for most uses. Other parts either followed the same process or re-used the low poly original models. This mix of methods worked, but mix also leads to a certain inconsistency in final result. Better planning could avoid this.

At this stage I had a low poly model and now needed to create my UVW maps for textures. 3DS has a great UVW Unwrap modifier to cut up your model and aid in laying it out. With the layouts done I then moved on to X-Normal, a free utility for creating Normal, Occlusion and other useful maps. A high poly model from Zbrush can be ‘decimated’ to reduce the polys without losing detail and then exported. The low and high poly are then taken to X-Normal and the high poly is then ‘projected’ onto the low poly model.

We then end up with our Normal maps, which keep our high poly detail, but allow us to use our low poly model in Unity:

Image

X-Normal also outputs other maps useful in texture creation. For the main texture I used the occlusion map and brought it into Photoshop where I painted in some colour and other details:

Image

Note the large amount of unused space in the top right – this is not best use and I could have spent more time optimising my layouts and combining other elements to better use space. A specular map was also created from slight adaptations to this main texture.

At this point I now had a full model, textured and ready to be placed in Unity. The final poly count was a ridiculous 15,500polys. This is near the same as Marcus Pheonix from Gears of War(!) and there’s no reason to have a robot character with this many polys in the sort of projects I am working on. Except of course for the fact I am inexperienced and not good enough yet!

However, it works and for now that’s the point. But I now needed to be able to animate and place this animation into Unity. 3DS has it’s own animation system called CAT, which comes with preset rigs you can adapt to your own characters:

Image

Image

While the arms, head and legs/feet can simply be parented to the bones, the main torso element and the hands are solid and require the bones to deform the models. 3DS utilises a ‘Skin’ modifier for this. When applied you can then change the ‘weight’ of each bone’s influence on each part of the mesh. Below you can see a ‘spine’ bone’s affect on the waist of the torso. At shoulder joints this can become problematic with the high amount of deformation and so fine work can be done on individual vertex’s to get it just right.

Image

With this done I moved onto some animation and worked up three different ‘setups’. To the left are three different ‘idle’ animations. To the right is a robot on a treadmill and in the middle a robot with an on/off switch.

Image

Unity comes with a ‘Ragdoll’ creator, which takes your rigged character and lets you setup a ragdoll with a couple of easy steps. However we need to then have our models swap out from the animated character to the rig when shot with a simple ‘laser’ style weapon.

Image

To each robot is a short script as follows:

using UnityEngine;
using System.Collections;

public class ragit : MonoBehaviour {

public GameObject ragdoll;  //in the editor we drag-drop our ragdoll to this

//The following function calls our ragdoll.

void OnBullet()

{

Vector3 startingVelocity = rigidbody.velocity;

GameObject rag = Instantiate(ragdoll, transform.position, transform.rotation) as GameObject;

MatchChildrenTransform(this.transform, rag.transform);
foreach(Rigidbody body in rag.GetComponentsInChildren<Rigidbody>())
{
// body.velocity = startingVelocity;
}

Destroy(this.gameObject);  //gets rid of our original after the ragdoll is called
}

//This next part is what matches our ragdoll’s body parts to the same transform and rotation as the original.

void MatchChildrenTransform(Transform source, Transform target)

{
if (source.childCount > 0) {
foreach (Transform sourceTransform in source)

{
Transform targetTransform = target.Find (sourceTransform.name);
if (targetTransform != null) {
targetTransform.localPosition = sourceTransform.localPosition;
targetTransform.localRotation = sourceTransform.localRotation;
MatchChildrenTransform (sourceTransform, targetTransform);
}
}
}
}

}

It works very nicely, however it’s worth noting the part that reads “// body.velocity = startingVelocity;” half way down, which adds the velocity of the original to the ragdoll. While this works in theory it made my own models tend to go insane with too much velocity and so I disabled it, meaning the robots simply drop where they stand.

The ‘gun’ attached to the FPS controller is a simply racast which ‘sends’ a message to what it hits to call the function “OnBullet()”:

using UnityEngine;
using System.Collections;

public class CamShoot : MonoBehaviour {

public RaycastHit hit;
public static Collider collider1 = new Collider();
private Ray ray;
private Vector3 vec;
private LayerMask layerMask;

void Update () {

// Find the centre of the Screen
vec.x = (float)Screen.width / 2;
vec.y = (float)Screen.height / 2;
vec.z = 0;

// Create the actual Ray based on the screen vector above
ray = camera.ScreenPointToRay(vec);

//The robots sit on layer ’12’, meaning it will only call if it hits the robot

layerMask = 1 << 12;

if(Input.GetMouseButton(0))
{

if (Physics.Raycast(ray, out hit, 50f, layerMask ))
{
collider1 = hit.collider;

//The important bit – where we ‘send’ the message to the object hit
hit.transform.SendMessage( “OnBullet”, SendMessageOptions.DontRequireReceiver );
Debug.DrawLine(transform.position, hit.point, Color.red, 2f);
}
}
}
}

We then end up with our poor tired friends slumped helplessly of the floor. The limbs are a little ‘rubbery’ here and more work could go into finessing how they work together to get a more ‘solid’ and substantial movement.

Image

I next moved onto basically the same setup, but now with the robot running on a treadmill. The idea here being the treadmill will make the body zip off the back, however it’s not quite as violent as I had hoped…. some more friction could help. The animation is also a little less believable then I had hoped, but there was little point spending a long time perfecting what is essentially pre-pre-alpha level work. The back foot can also be seen clipping the treadmill – which did not happen in the original animation and seems to be an error that has crept in, perhaps on export.

Image

Finally I decided to re-create the Most Useless Machine Ever!, but with a robot. It’s actually pretty simple, but with some tricky work to get it to reset (and change the lights on and off). There is a ‘timer’ which resets the logic, however if you shoot the button more than once it will reset the timer and it won’t reset properly. So… don’t do that.

Image

And that’s it! It was a fun little side project. I’ve learned a great deal, but I think it’s time to get back to the Tower Defence Game…

About these ads

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