For our last assignment, we were required to create a 3D character, use C# programming language to control the character, and put that them in an environment. We used Adobe Fuse for character creation and Mixamo to apply pre-made animations.
This is my character, Jess at Burning Man in the year 3000, when the event will inevitably be hosted on the moon.
Jess can be controlled with the following key presses:
- walk forward [ up arrow ]
- walk backward [ back arrow ]
- walk forward diagonally [ up arrow + left arrow, up arrow + right arrow ]
- air-guitar playing animation [ key 1 ]
- robot dance animation [ key 2 ]
- fall flat animation [ mouse click ]
- wait animation (randomly picks between two different options) [ key 5 ]
[video width="2880" height="1800" mp4="http://www.chrissyelie.com/wp-content/uploads/2016/12/Documentation_unity.mp4"][/video]
Here is the C# code for controlling the animations above:
using UnityEngine; using System.Collections;
public class player : MonoBehaviour {
public Animator anim; public Rigidbody rbody;
private float inputH; private float inputV; // Use this for initialization void Start () { anim = GetComponent<Animator>(); rbody = GetComponent<Rigidbody> ();
} // Update is called once per frame void Update () { if(Input.GetKeyDown ("1")) { anim.Play ("guitar_playing", -1, 0f); } if (Input.GetKeyDown ("2")) { anim.Play ("robot_hip_hop_dance", -1, 0f); } if (Input.GetMouseButtonDown (0)) { anim.Play ("fall_flat"); } if (Input.GetKeyDown ("5")) { int n = Random.Range(0, 2); if (n == 0) { anim.Play("WAIT01", -1, 0f); } else { anim.Play("WAIT03", -1, 0f); } }
inputH = Input.GetAxis ("Horizontal"); inputV = Input.GetAxis ("Vertical");
anim.SetFloat ("inputH", inputH); anim.SetFloat ("inputV", inputV);
float moveX = inputH * 20f * Time.deltaTime; float moveZ = inputV * 50f * Time.deltaTime;
if (moveZ <= 0f) { moveX = 0f; }
rbody.velocity = new Vector3 (moveX, 0f, moveZ); } }