Wednesday, 27 August 2014

Character to Player: Bringing Characters to Life

Bringing Characters to Life

from my last blog about rigging here it a continued part about bringing life onto a character.
http://behaviouralmodellingapprentice.blogspot.com/2014/07/character-rigging.html

Once you have rigged your character in mixamo, export it onto unity in .fbx
Once on Unity Make you have for an asset a Sample Asset. If you don't it available for unity 4.3 or higher at the asset store.

if you already have you may proceed.


Now go to Sample Assets > Characters > Third Person Character > Prefab

















In the Third Person Character folder you'll find two ready-made character prefabs, which are used in the third person character sample scenes. These prefabs demonstrate how you can use the third person characters scripts and animations we've included, including an AI-controlled variant which is able to walk towards a specified target, or follow a waypoint-based route.

The simplest way to get started setting up your own character is to take our Third Person Character and replace the art with your own model. To do so, make sure you've imported your own rigged model with a Humanoid avatar, then follow these steps:

1) Start with a suitable scene. There ought to be enough flat ground to walk around on.

2) Place the "Third Person Character" prefab in the scene.



3) Unfold the Third Person Character hierarchy in the hierarchy window, and delete the "Ethan" child object.

4) Place your own character model as a child of the Third Person Character, in place of Ethan.

5) Make sure your character model's position in the inspector is set to zero on X and Z, and that it's Y position is appropriately adjusted so that your character's feet are at the same position as the Third Person Character GameObject. (if you find it easier, you could add your character first before deleting Ethan, so that you can use Ethan's feet as a guide for where your character's feet should be)


7) Hit play, and try controlling your character!

You'll probably want to add a camera rig so that the camera follows the character as it runs off. See the Camera Rig guidelines for instructions on how to do that.

The Third Person Character script exposes a number of properties which determine the jump power, the amount of control while in air, and various other speed and behaviour modifiers. For more detail about each setting, see the comments in the script.

The ThirdPersonUserControl script takes input from the "CrossPlatformInput" class included in the sample assets, however if you're not targeting mobile or prefer to use a different system to read input, you can simply use Unity's built-in Input class in place of CrossPlatformInput. For more information, see the Cross Platform Input guidelines.

The sample scenes provided works on standalone and also include cross platform touch controls which are set up and ready to publish to mobile.

The ThirdPersonAIControl component can be added instead of the user control component, allowing the character to be AI controlled. This relies on a NavMeshAgent to pathfind the way to the target. The NavMeshAgent should be a child object of the Character, as demonstrated in the AI Character Prefab provided. If you want to create your own AI characters, you can follow the steps above, but start with the AI prefab we provided.

Unity3D - Collision Part 2


Wheel Collider

The Wheel Collider is a special collider for grounded vehicles. It has built-in collision detection, wheel physics, and a slip-based tire friction model. It can be used for objects other than wheels, but it is specifically designed for vehicles with wheels.



PROPERTIES


CenterCenter of the wheel in object local space.
RadiusRadius of the wheel.
Suspension DistanceMaximum extension distance of wheel suspension, measured in local space. Suspension always extends downwards through the local Y-axis.
Suspension SpringThe suspension attempts to reach a Target Position by adding spring and damping forces.
SpringSpring force attempts to reach the Target Position. A larger value makes the suspension reach the Target Position faster.
DamperDampens the suspension velocity. A larger value makes the Suspension Spring move slower.
Target PositionThe suspension's rest distance along Suspension Distance. 0 maps to fully extended suspension, and 1 maps to fully compressed suspension. Default value is zero, which matches the behavior of a regular car's suspension.
MassThe Mass of the wheel.
Forward/Sideways FrictionProperties of tire friction when the wheel is rolling forward and sideways.

Unity3d - Collision Part 1

Colliders :


Colliders are another kind of component that must be added alongside the Rigidbody in order to allow collisions to occur. If two Rigidbodies bump into each other, the physics engine will not calculate a collision unless both objects also have a Collider attached. Collider-less Rigidbodies will simply pass through each other during physics simulation.
Add a Collider with the Component->Physics menu. View the Component Reference page of any individual Collider for more specific information:  

Types Of Colliders :

1) Box Collider - primitive shape of a cube2) Sphere Collider - primitive shape of a sphere
3) Capsule Collider - primitive shape of a capsule
4) Mesh Collider - creates a collider from the object's mesh, cannot collide with another Mesh Collider
5) Wheel Collider - specifically for creating cars or other moving vehicles

Box Collider
The Box Collider is a basic cube-shaped collision primitive.

PROPERTIES
Material
Reference to the Physic Material that determines how this Collider interacts with others.
IsTrigger
 If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
Size
The size of the Collider in the X, Y, Z directions.
Center
The position of the Collider in the object's local space.
Sphere Collider

The Sphere Collider is a basic sphere-shaped collision primitive.

PROPERTIES

Material
Reference to the Physic Material that determines how this Collider interacts with others.
IsTrigger
If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
Radius
The size of the Collider.
Center
The position of the Collider in the object's local space.

Capsule Collider

The Capsule Collider is made of two half-spheres joined together by a cylinder. It is the same shape as the Capsule primitive.

PROPERTIES

Material
Reference to the Physic Material that determines how this Collider interacts with others.
Is Trigger
If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
Radius
The radius of the Collider's local width.
Height
The total height of the Collider.
Direction
The axis of the capsule's lengthwise orientation in the object's local space.
Center
The position of the Collider in the object's local space

Mesh Collider

The Mesh Collider takes a Mesh Asset and builds its Collider based on that mesh. It is far more accurate for collision detection than using primitives for complicated meshes. Mesh Colliders that are marked as Convex can collide with other Mesh Colliders.

PROPERTIES

Material
Reference to the Physic Material that determines how this Collider interacts with others.
Is Trigger
If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
Mesh
Reference to the Mesh to use for collisions.
Smooth Sphere Collisions
When this is enabled, collision mesh normals are smoothed. You should enable this on smooth surfaces eg. rolling terrain without hard edges to make sphere rolling smoother.
Convex
If enabled, this Mesh Collider will collide with other Mesh Colliders. Convex Mesh Colliders are limited to 255 triangles.


Animator Scripting

Animator Scripting

Unity’s Animation System allows you to create beautifully animated skinned characters. The Animation System supports animation blending, mixing, additive animations, walk cycle time synchronization, animation layers, control over all aspects of the animation playback (time, speed, blend-weights), mesh skinning with 1, 2 or 4 bones per vertex as well as supporting physically based rag-dolls and procedural animation. To obtain the best results, it is recommended that you read about the best practices and techniques for creating a rigged character with optimal performance in Unity on the Modeling Optimized Characters page.

Making an animated character involves two things; moving it through the world and animating it accordingly. If you want to learn more about moving characters around, take a look at the Character Controller page. This page focuses on the animation. The actual animating of characters is done through Unity’s scripting interface.

http://docs.unity3d.com/Manual/ModelingOptimizedCharacters.html - Modeling Optimized Characters page
http://docs.unity3d.com/Manual/class-CharacterController.html - Character Controller page

Animation View

Using the Animation View 

The Animation View can be used to preview and edit Animation Clips for animated Game Objects in Unity. The Animation View can be opened from the Window->Animation menu.

Viewing Animations on a GameObject

The Animation View is tightly integrated with the Hierarchy View, the Scene View, and the Inspector. Like the Inspector, the Animation View will show whatever Game Object is selected. You can select a Game Object to view using the Hierarchy View or the Scene View. (If you select a Prefab in the Project View you can inspect its animation curves as well, but you have to drag the Prefab into the Scene View in order to be able to edit the curves.)

The Animation View shows the Game Object selected in the Hierarchy View
The Animation View shows the Game Object selected in the Hierarchy View

At the left side of the Animation View is a hierarchical list of the animatable properties of the selected Game Object. The list is ordered by the Components and Materials attached to the Game Object, just like in the Inspector. Components and Materials can be folded and unfolded by clicking the small triangles next to them. If the selected Game Object has any child Game Objects, these will be shown after all of the Components and Materials.

The property list to the left in the Animation View shows the Components and Materials of the selected Game Object, just like the Inspector
The property list to the left in the Animation View shows the Components and Materials of the selected Game Object, just like the Inspector

Creating a New Animation Clip

Animated Game Objects in Unity need an Animation Component that controls the animations. If a Game Object doesn’t already have an Animation Component, the Animation View can add one for you automatically when creating a new Animation Clip or when entering Animation Mode.
To create a new Animation Clip for the selected Game Object, click the right of the two selection boxes at the upper right of the Animation View and select [Create New Clip]. You will then be prompted to save an Animation Clip somewhere in your Assets folder. If the Game Object doesn't have an Animation Component already, it will be automatically added at this point. The new Animation Clip will automatically be added to the list of Animations in the Animation Component.

Create a new Animation Clip
Create a new Animation Clip

In the Animation View you can always see which Game Object you are animating and which Animation Clip you are editing. There are two selection boxes in the upper left of the Animation View. The left selection box shows the Game Object with the Animation Component attached, and the right selection box shows the Animation Clip you are editing.

The left selection box shows the Game Object with the Animation Component attached, and the right selection box shows the Animation Clip you are editing.
The left selection box shows the Game Object with the Animation Component attached, and the right selection box shows the Animation Clip you are editing.

Animating a Game Object

To begin editing an Animation Clip for the selected Game Object, click on the Animation Mode button.


This will enter Animation Mode, where changes to the Game Object are stored into the Animation Clip. (If the Game Object doesn’t have anAnimation Component already, it will be automatically added at this point. If there is not an existing Animation Clip, you will be prompted to save one somewhere in your Assets folder.)
You can stop the Animation Mode at any time by clicking the Animation Mode button again. This will revert the Game Object to the state it was in prior to entering the Animation Mode.
You can animate any of the properties shown in the property list of the Animation View. To animate a property, click on the Key Indicator for that property and choose Add Curve from the menu. You can also select multiple properties and right click on the selection to add curves for all the selected properties at once. (Transform properties are special in that the .x.y, and .z properties are linked, so that curves are added three at a time.)

Any property can be animated by clicking on its Key Indicator or by right clicking on its name
Any property can be animated by clicking on its Key Indicator or by right clicking on its name

When in Animation Mode, a red vertical line will show which frame of the Animation Clip is currently previewed. The Inspector and Scene View will show the Game Object at that frame of the Animation Clip. The values of the animated properties at that frame are also shown in a column to the right of the property names.

In Animation Mode a red vertical line shows the currently previewed frame
In Animation Mode a red vertical line shows the currently previewed frame

You can click anywhere on the Time Line to preview or modify that frame in the Animation Clip. The numbers in the Time Line are shown as seconds and frames, so 1:30 means 1 second and 30 frames.


You can also use the following keyboard shortcuts to navigate between frames:
  • Press Comma (,) to go to the previous frame.
  • Press Period (.) to go to the next frame.
  • Hold Alt and press Comma (,) to go to the previous key frame.
  • Hold Alt and press Period (.) to go to the next key frame.
In Animation Mode you can move, rotate, or scale the Game Object in the Scene View. This will automatically create Animation Curves for the position, rotation, and scale properties of the Animation Clip if they didn’t already exist, and keys on those Animation Curves will automatically be created at the currently previewed frame to store the respective Transform values you changed.
You can also use the Inspector to modify any of the animatable properties of the Game Object. This too will create Animation Curves as needed, and create keys on those Animation Curves at the currently previewed frame to store your changed values. Properties that are not animatable are grayed out in the Inspector while in Animation Mode.


You can also manually create a keyframe using the Keyframe button. This will create a key for all the curves that are currently shown in the Animation View. If you want to only show curves for a subset of the properties in the property list, you can select those properties. This is useful for selectively adding keys to specific properties only.

When selecting a property in the property list, only the curve for that property is shown.
When selecting a property in the property list, only the curve for that property is shown.

Playback

The Animation Clip can be played back at anytime by clicking the Play button in the Animation View.


The playback will loop within the time range that is shown in the Time Line. This makes it possible to focus on refining a small part of the Animation Clip that is being worked on, without having to play back the entire length of the clip. To play back the whole length of the Animation Clip, zoom out to view the entire time range, or press F to Frame Select with no keys selected. 

Tuesday, 26 August 2014

Animation Properties


Using the inspector comes in three parts , Model ,Rig and Animation. Today we'll be looking at Animations.





The ”position”,”rotation” and ”scale” error will allow us to get the position if its with a smaller value.and the less compression that we will get.
The clips section will show you what animation you have in the model.
When one of this clips are selected, all of the option for that specific clip are available. 


Below the timeline is the loop pose.






If the loop pose is checked,unity will try and mesh the start and the end to make it look smoother.The cycle offset is for mirroring animation.If the bake into pose is checked, the avatar will not rotate with any turning within the animation.Used this if the animation is running in a straight line so that any deviation from a straight line is not affected,the root transform rotation can either be based on the body orientation at the start of the animation or the original source file of the animation.As with root transformation,

if checked in the bake into pose,the avatar will not move up or down in the animation. There is a few that it can be based on. Original takes from the original file.Otherwise it can be based on the avatar's center of mass or its feet. 


Animator Controller Layers


Animation Layers

Unity uses Animation Layers for managing complex state machines for different body parts. An example of this is if you have a lower-body layer for walking-jumping, and an upper-body layer for throwing objects / shooting.
You can manage animation layers from the Layers Widget in the top-left corner of the Animator Controller.
You can add a new layer by pressing the + on the widget. On each layer, you can specify the body mask (the part of the body on which the animation would be applied), and the Blending type. Override means information from other layers will be ignored, while Additive means that the animation will be added on top of previous layers.
The Mask property is there to specify the body mask used on this layer. For example if you want to use upper body throwing animations, while having your character walk or run, you would use an upper body mask, like this:

Animation Layer syncing 

Sometimes it is useful to be able to re-use the same state machine in different layers. For example if you want to simulate “wounded” behavior, and have “wounded” animations for walk / run / jump instead of the “healthy” ones. You can click the Sync check box on one of your layers, and then select the layer you want to sync with. The state machine structure will then be the same, but the actual animation clips used by the states will be distinct.