Unity – Spaceship Shooting Game – JS – Laser Bolt

Unity – Spaceship Shooting Game – JS – Laser Bolt

1. Create the Prefab ‘Bolt’
2. The prefabs needs inside Inspector:
– Transform
– Rigid Body
– Capsule Collider: check ‘Is Trigger’

– Mover.js

#pragma strict

var speed : float; // Assign this inside Inspector

function Start () : void {
    // forward is the Z Axis
    rigidbody.velocity = transform.forward * speed;
}

Inspector> Mover (Script)
– Speed: 20

3. Create a Prefab ‘Player’ (it is the spaceship)
4. Create an Empty Object ‘Shot Spawn’ (produttore di spari)
5. DRAG AND DROP ‘Shot Spawn’ over Hierarchy> ‘Player’, now ‘Shot Spawn’ is child of ‘Player’
6. DRAG AND DROP ‘Bolt Prefab’ over Hierarchy> ‘Shot Spawn’, now ‘Bolt Prefab’ is child of ‘Shot Spawn’

At the end the Hierarchy will be:

Player
– Shot Spawn
– Bolt Prefab

Assign to ‘Player’ PlayerController.js:

#pragma strict

class Boundary
{
    // Theese variables are public to make the code easy-reusable
    // You can setup theese variables from Inspector
    var xMin : float;
    var xMax : float;
    var zMin : float;
    var zMax : float;
}

var speed : float;
var tilt : float;
var boundary : Boundary;

var shot : GameObject;     // Inspector -> assign Bolt Prefab
var shotSpawn : Transform; // Inspector -> assign Shot Spawn Empty Object
var fireRate : float;      // Inspector -> 0.25 (seconds) = 4 shot per second

private var nextFire : float;

function Update () {
    // Get Input Fire button
    if (Input.GetButton("Fire1") && Time.time > nextFire)
    {
        nextFire = Time.time + fireRate;
        // Return the clone of the GameObject, position, rotation if user click Fire button 
        Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
        // Assign an audio file inside Inspector
        audio.Play ();
    }
}

function FixedUpdate () {
     // Get User Input START
     var moveHorizontal : float= Input.GetAxis ("Horizontal");
     var moveVertical : float= Input.GetAxis ("Vertical");
     // Get User Input END

     // Move the GameObject
     var movement : Vector3= new Vector3 (moveHorizontal, 0.0f, moveVertical);
    rigidbody.velocity = movement * speed;

    // Limitate movement inside the screen START
    rigidbody.position = new Vector3 
    (
        Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), 
        0.0f, 
        Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
    );
    // Limitate movement inside the screen END

    // Tilt movement START
    rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
    // Tilt movement END
}

Hierarchy> Player> Shot Spawn> Bolt CANC to delete
Se non si cancella questo oggetto, all’inizio del gioco la nostra astronave sparerà subito un colpo, invece noi vogliamo che non vengano emessi colpi fino a che il tasto fire resta inutilizzato.

7. MAIN tOP MENU> GameObject> Cube and name it ‘Boundary’
8. Hierarchy> select ‘Cube’> Inspector>
– Transform> small gear icon> Reset
– Mesh Render> uncheck
– Box Collider> check ‘Is Trigger’
9. Scale the box to surround all your game area

10. Create and assign to ‘Boundary’ DestroyByBoundary.js

#pragma strict

// Destroy Game Objects START
function OnTriggerExit(other : Collider)
{
    // Destroy all GameObjects WITH COLLIDER that run away THIS Collider
    // The GameObject WITHOUT COLLIDER will not be detroyed!!!
    Destroy(other.gameObject);
}
// Destroy Game Objects END

11. Hierarchy> ‘Boundary’> Inspector> Remove ‘Mesh Filter”Mesh Renderer’

By |Unity3D, Video Games Development|Commenti disabilitati su Unity – Spaceship Shooting Game – JS – Laser Bolt

Unity – Spaceship Shooting Game – JS – Spaceship

Unity – Spaceship Shooting Game – JS – Spaceship

1. Hierarchy> select the Space Ship GameObject> Inspector> ‘Add Component’> Scripts> JS Script

The code of ‘PlayerController.js’:

#pragma strict

class Boundary
{
    // Theese variables are public to make the code easy-reusable
    // You can setup theese variables from Inspector
    var xMin : float;
    var xMax : float;
    var zMin : float;
    var zMax : float;
}

// Theese variables are public to make the code easy-reusable
// You can setup theese variables from Inspector
var speed : float;
var tilt : float;
var boundary : Boundary;

function FixedUpdate () {
     // Get User Input START
     var moveHorizontal : float= Input.GetAxis ("Horizontal");
     var moveVertical : float= Input.GetAxis ("Vertical");
     // Get User Input END

     var movement : Vector3= new Vector3 (moveHorizontal, 0.0f, moveVertical);
    rigidbody.velocity = movement * speed;

    // Limitate movement inside the screen START
    rigidbody.position = new Vector3 
    (
        Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), 
        0.0f, 
        Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
    );
     // Limitate movement inside the screen END

    // Tilt movement START
    rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
    // Tilt movement END
}

2. Hierarchy> select the Space Ship GameObject> Inspector> ‘PlayerController.js’

– Speed
– Tilt

Boundary
– XMin: to get this value you can go to ‘Game’ view, select ‘Space Ship’ GameObject> Inspector> Transform> change X Position

– XMax: to get this value you can go to ‘Game’ view, select ‘Space Ship’ GameObject> Inspector> Transform> change X Position

– ZMin: to get this value you can go to ‘Game’ view, select ‘Space Ship’ GameObject> Inspector> Transform> change Z Position

– ZMax: to get this value you can go to ‘Game’ view, select ‘Space Ship’ GameObject> Inspector> Transform> change Z Position

By |Unity3D, Video Games Development|Commenti disabilitati su Unity – Spaceship Shooting Game – JS – Spaceship

3DS MAX – Biped to Unity Game Engine

3DS MAX – Biped to Unity Game Engine

Rigging a character using Biped and Skin in 3DS Max, animate and export it to Unity Game Engine.

Scene Setup

1. Setup the units using the parameters in the link below:

http://www.lucedigitale.com/blog/3ds-max-micro-reference-manual-unit-setup-interiors/

2. Create and animate a mesh with Biped + Skin Modifier.
You have not to use ‘Physique Modifier’ because ‘Skin Modifier’ has best support in FBX format.

3. Select the mesh and give it a name, this name will be the name of ‘Mesh’ component inside Unity

FBX Export

4. Select the mesh> MAIN TOP LEFT BUTTON> File> Export> Export Selected> FBX> give it a name, it will be the name of the Asset inside Unity.

FBX Export setup:

>Geometry
check TurboSmooth
check Convert Deforming Dummies to Bones
check Preserve edge orientation

>Animation
check Animation

>Deformations
check Deformations
check Skins
check Morphs

>Unroll Rotations
check Follow Y-Up

>Scale Factor
check Automatic (1 unity = 1 3DSMax meter)

>Axis Conversion
Up Axis = Y-up

>FBX File Format
Type: Binary
Version: FBX 2013

Unity – Import

1. Open Unity> MAIN TOP MENU> Assets> Import New Asset…> select the .FBX file

2. Project> the new Asset (the blue box icon) with the .FBX file name> DRAG AND DROP into Viewport the blue box icon

You will see:

Viewport>

1 unity = 1 3DSMax meter

Project>

Asset blue box icon (file name)
-> Inspector> Rig> Animation Type: Generic> ‘Apply’ button
-> Model> Scale Factor: 0.01 (the original 3DSMax scene was in centimeters), resize if you need> ‘Apply’ button
-> Animations> + or – to cut Takes, Loop Time
– Mesh
– Take 001 (the animation)
– Avatar
– Bip001
– Material

Hierarchy>

Asset (file name) -> Transform + Animator
– Bip001
— Bip001 Pelvis
— Bip001 Spine -> Transform, you can re-animate bones with the transform tools!
— …
– Mesh -> Transform + Skinned Mesh Renderer + Material

Unity – Apply Animation

1. Projects> RMB> Create> Animator Controller> name it ‘PlayerAnimator’

2. MAIN TOP MENU> Window> Animator

3. Project> Take 001 DRAG AND DROP into Animator window, ‘Take 001’ turn in yellow because it is the default animation

4. Project> Animator Controller ‘PlayerAnimator’ DRAG AND DROP into Hierarchy> Asset (file name)> Animator> Controller

5. MAIN TOP BUTTON ‘Play’

Unity – Multiple Takes

Solution one

1. Inside 3DSMax you can create multiple animations inside timeline, example

a. frame 0-25 walk
b. frame 26-50 run
c. frame 51-100 die

2. File> Export Selected> FBX

FBX Export setup:

>Bake Animation
check Bake Animation
Start: 0 – End: 25

Save as walk.fbx

3. Unity> MAIN TOP MENU> Assets> Import New Asset…> walk.fbx

Project> you will find the Take001 animation of 1-25

Repeat the operation for all the takes you need.

Solution two

1. Inside 3DSMax you can create multiple animations inside timeline, example

a. frame 0-25 walk
b. frame 26-50 run
c. frame 51-100 die

2. File> Export Selected> FBX

FBX Export setup:

>Bake Animation
check Bake Animation
Start: 0 – End: 100

Save as walk.fbx, alla animations will be stored in a single file.

3. Unity> MAIN TOP MENU> Assets> Import New Asset…> walk.fbx

Project> select the new Asset (blue box icon)> Inspector> Animations> Clips use + or – to cut the Take using the procedure below:

a. + icon
b. Give the name
c. setup ‘Start’ ‘End’
d. ‘Apply’ button

Repeat the operation for all the takes you need.

Project> you will find the Take001 animation of 1-25 – Take002 etc…

By |Unity3D, Video Games Development|Commenti disabilitati su 3DS MAX – Biped to Unity Game Engine

3DS MAX – Rigging – CAT – Skin

3DS MAX – Rigging – CAT – Skin

Rigging a character using CAT and Skin in 3DS Max.

Scene Setup

1. Setup the units using the parameters in the link below:

http://www.lucedigitale.com/blog/3ds-max-micro-reference-manual-unit-setup-interiors/

Create Mesh

2. Create the mesh of the character, and Freeze it.

Create CAT skeleton

3. RIGHT COLUMN> Create> Helpers> CATParent> CATRig Load Save> Bip01 (or ather skeleton)> CLICK AND DRAG to create the skeleton

4. CATRig Parameters>
– Name: give it a name
– CATUnits Ratio: give the height of the character

5. Select a CAT object> RIGHT COLUMN> Motion> modify the skeleton to fit it inside the mesh

a. Move the helper (the tringle with arrow)
b. Move the foot IKTarget (the rectangle under the foot)
c. Move the PelvisBone (the cube inside the pelvis character)
d. Move-Scale-Rotate joints of others body parts etc…

Mirror body parts:

e. Select the right Arm> RIGHT COLUMN> Copy Limb Setting> select the left Arm> Paste/Mirror Limb Settings

Skin

6. Select the mesh> MAIN TOP MENU> Modifiers> Animation> Skin

7. Skin> Parameters> Bones: ‘Add’, add all bones, NOt ADD the helpers!

8. Setup Skin Envelopes and Vertex Weigths, see the lesson:

http://www.lucedigitale.com/blog/3ds-max-skin/

Animate

9. Select a CAT object> RIGHT COLUMN> Motion> Layer Manager> Abs, select the icon with a little green running man

10. Layer Manager> click Setup/Animation Mode Toggle, the icon change to a ‘Green Play’ button

11. Timeline> Play the animation

By |3D Graphic, 3DS Max|Commenti disabilitati su 3DS MAX – Rigging – CAT – Skin

3DS MAX – Skin

Skinnin Character

1. Select the mesh> MAIN TOP MENU> Modifier> Animation> Skin

2. Skin> Parameters> Bones: ‘Add’> select all the Biped objects

Edit Envelopes

3. Skin> Parameters> Edit Envelopes> Viewport> MOVE the envelope’s handles

Viewport> RMB over Envelop Yellow Line> Add Cross Section> LMB over Envelop Yellow Line to create a new Cross Section

Copy Envelope from left to right

Viewport> RMB over Envelop Yellow Line> Copy Envelope

Viewport> RMB over Envelop Yellow Line> Paste Envelope

Paint Weight

4. Skin> Parameters> Weight Properties> ‘Weight Table’> select Vertices> DRAG to change values

5. Skin> Parameters> Weight Properties> ‘Paint Weights’

Copy Weiight from left to right

6. Skin> Parameters> Mirror Parameters> ‘Mirror Mode’

By |3D Graphic, 3DS Max|Commenti disabilitati su 3DS MAX – Skin