Monday, March 18, 2019

Scripts: Camera Controller

I am now posting all of the scripts that I created for this project.

Camera controller, controls the camera through mouse input, rotating it around the character on both X and Y axes:


Scripts: IK Controller

I am now posting all of the scripts that I created for this project.

IK Control, controls the position of the hands using a simple IK solver:





Scripts: Animator Controller

I am now posting all of the scripts that I created for this project.

Animator controller, controls all animations, state machine behaviors, contains all functionality for controlling exactly when animations play by any means necessary:







Scripts: Movement Controller

I am now posting all of the scripts that I created for this project.

The Movement Controller controls all of the movement (forces, translations, etc.) being applied to the character controller:





This Week's Progress in Unity

This week I created a camera controller, re-parenting several components of my character game object's hierarchy in the scene:



Earlier, the camera was parented inside of the character, and all of the components including scripts were on the outermost object in the hierarchy. Now, there is a parent null object underneath which the character rig and camera reside in two separate game objects. The camera is now parented underneath a null object resting at the pivot point of the character, (0, 0, 0) in local space.



It's nice that my character now has a decent camera controller, however, his functionality is now suffering from a few bugs. First, the character rotates downward after moving. This is because I set the characters transform.rotation to be equal with that of the camera, and the camera is looking downward. I will have to find a way to rotate the character back up so on the x axis so that its forward vector is parallel with that of the world's.   

The second, I think, is due to the re-parenting I did of the camera and character controller, because the colliders are no longer working, so the landing animations no longer play. I will re-parent the camera, and apply the animator component and all other scripts and components to the top/root level of the hierarchy.

The last issue I have to fix is that the IK aiming is also malfunctioning, flickering instead of staying constant. The left hand is no longer moving to the position of the ik handle on the rifle. I don't know why this is taking place, but the issue started when I re-parented the camera controller object, if that is any clue. 


I have started to build the functionality for the character's melee system. There is a null object that the left-hand IK handle snaps to when it is toggled active. Right now it's a bit choppy, but I will use this to give my character the ability to strike at targets, his fist automatically moving to contact. I will need to figure out how to achieve smooth blending from null objects to IK handles for all Unity IK functionality in order for the animations to be believable.

Project Roadmap


Project Roadmap

I have revised last week's plan of action a bit to account for what I accomplished this week, and what I plan to accomplish in the weeks following:

- Week 7: 

  •  Character's rig completed
  • Reviewed re-targeting MoCap animations in Motion Builder
  • Learned how to use Unity Mecanim for editing and re-targeting animations.
  • Learned how to change root motion of animations in the inspector upon import, as well as in the Animation editor window.


-Week 8: 

  • Re-targeted all animations and got them into Unity.
  • Used Unity IK to bind left hand to rifle.
  • Used blend trees to blend between running in different directions.
  • Used animation layers to mask lower body running animations, and upper body running and shooting animations.
  • Restructured project, separating animation libraries to separate Unity project, for organizational purposes and to free up space in project.
  • Tried to add melee attack animation blend tree, which is still buggy. I may need to simplify it a great deal.


-Week 9: 

  • Re-imported all fixed Animations into Unity
  • Added jumping and landing animation and functionality. The Character now has a takeoff jumping, midair jumping, and soft landing animations. 
  • When the space bar is pressed or held, the character somersaults into the air. Holding down the space bar causes the character to somersault in the air for a longer period of time, and ascend to a greater height before being pulled back down to the ground.
  • Used Unity IK to begin adding aiming functionality. Character now aims forward, but additional animation correcting is required.

-Week 10:
  •  Continued working on jump and landing functionality.
    • Added hard landing animation, for a total of 2 different landing animations.
      • Still buggy
    • Added animation for jumping while shooting, a falling idle where avatar masks are used to transition the upper body from falling/airborne to shooting while falling/airborne.
    • Worked on fixing jumping animation problem/glitch:
      • Build functionality to detect how high character is in the air in order to smoothly transition between falling and landing animations. 
      • Calculated the rate of change in falling velocity based on how high the character is in the air, or use raycast, to determine when to start blending from falling to landing animation.
        • Still buggy.
  • Began building melee attack functionality
-Week 11:
  • Work on fixing jumping animation problem/glitch:
      • Continue building functionality to detect how high character is in the air in order to smoothly transition between falling and landing animations. 
      • Calculate the amount of force applied before jumping, based on a set of parameters.
      • Calculate the rate of change in falling velocity based on how high the character is in the air, or use raycast, to determine when to start blending from falling to landing animation.
  • Use IK to move fist to contact during melee attack animation.
  • Begin adding functionality for detecting when character should touch a nearby wall.
  • Look at smoothly blending IK weights to achieve smooth transition between IK handle control and animation.
  • Use IK to achieve foot planting (lowest priority)
  • Continue building aiming system, rotate spine bones (spine, chest, neck, head) to follow target.
  • If all of the above goals are completed, work on the Week 11 tasks in the spreadsheet:
    • Wall jumping
    • Ledge grab
    • Bullet stopping
  • Add as much functionality as possible in time remaining using all Unity Mecanim tools possible.
  • Continue working on character controller, adding more functionality. Add Unity IK functionality, troubleshoot problems if need be.

Wednesday, March 13, 2019

Project Roadmap


This is my updated task plan for the remainder of this quarter. I may cut certain items from this list in the event that I have over-scoped. Items that are lower priority are certainly at risk to be cut.

Going Forward

I have revised last week's plan of action a bit to account for what I accomplished this week, and what I plan to accomplish in the weeks following:

- Week 7: 

  •  Character's rig completed
  • Reviewed re-targeting MoCap animations in Motion Builder
  • Learned how to use Unity Mecanim for editing and re-targeting animations.
  • Learned how to change root motion of animations in the inspector upon import, as well as in the Animation editor window.


-Week 8: 

  • Re-targeted all animations and got them into Unity.
  • Used Unity IK to bind left hand to rifle.
  • Used blend trees to blend between running in different directions.
  • Used animation layers to mask lower body running animations, and upper body running and shooting animations.
  • Restructured project, separating animation libraries to separate Unity project, for organizational purposes and to free up space in project.
  • Tried to add melee attack animation blend tree, which is still buggy. I may need to simplify it a great deal.


-Week 9: 

  • Re-imported all fixed Animations into Unity
  • Added jumping and landing animation and functionality. The Character now has a takeoff jumping, midair jumping, and soft landing animations. 
  • When the space bar is pressed or held, the character somersaults into the air. Holding down the space bar causes the character to somersault in the air for a longer period of time, and ascend to a greater height before being pulled back down to the ground.
  • Used Unity IK to begin adding aiming functionality. Character now aims forward, but additional animation correcting is required.

-Week 10:

  • Continue building aiming system, rotate spine bones (spine, chest, neck, head) to follow target.
  •  Continue working on jump functionality.
    • Add hard landing and rolling animations, for a total of 3 different landing animations.
    • Add animation for jumping while shooting, a falling idle where avatar masks are used to transition the upper body from falling/airborne to shooting while falling/airborne.
    • Fix jumping animation problem/glitch:
      • Build functionality to detect how high character is in the air in order to smoothly transition between falling and landing animations. 
      • Calculate the amount of force applied before jumping, based on a set of parameters.
      • Calculate the rate of change in falling velocity based on how high the character is in the air, or use raycast, to determine when to start blending from falling to landing animation.
  • Use IK to move fist to contact during melee attack animation.
  • Begin adding functionality for detecting when character should touch a nearby wall.
  • Look at smoothly blending IK weights to achieve smooth transition between IK handle control and animation.
  • Use IK to achieve foot planting (lowest priority)

-Week 11:
  • If all of the above goals are completed, work on the Week 11 tasks in the spreadsheet:
    • Wall jumping
    • Ledge grab
    • Bullet stopping
  • Add as much functionality as possible in time remaining using all Unity Mecanim tools possible.
  • Continue working on character controller, adding more functionality. Add Unity IK functionality, troubleshoot problems if need be.
  • Master's thesis research, read articles, find new ones, post to blog. What am I doing for my master's thesis? Why? How will this advance the given field?

Sunday, March 10, 2019

Further Work on Aiming and Jumping

Here, I demonstrate my jumping mechanic and rifle aiming. Both are still in progress, this is an update to show the advancements that have been made so far.

I have used Unity IK to correct the position of the characters hands and rifle while aiming, so that he aims completely forward, in the direction of the camera. Some additional work is required because his hands freeze in that position, which looks awkward, and his torso also needs to be rotated to match where the rifle is aiming. There is also no rotation in the Y axis, and no animation for when he is idle and turning left and right with the camera. I will fix those issues as well to create a more animated character.



I show here my character in a test environment, downloaded from the Unity Asset store. This is just to have scale reference, and to also be able to see how fast he is moving, how high he is jumping, etc. This is where I demonstrate my jumping mechanic so far. He now falls faster and can jump higher or lower depending on how long the player holds the space bar. I still plan on adding two more types of landing, the hard landing, and rolling. I will also add jumping in all directions, because right now he only jumps forward. In addition, a shooting midair idle animation that can be transitioned to while the player is somersaulting through the air is needed.


Cursor Locked Mode

In Unity, you can lock the state of the cursor while in play mode, effectively turning the cursor invisible and constraining it to the center of the screen so that you don't accidentally click on anything while playing, which can happen often and is very problematic. Being able to lock the cursor is very helpful for both playing and testing games. These are the two lines of code that do the trick, tough some additional scripting may be required:

  1.         lockMode = CursorLockMode.Locked;
  2.         Cursor.lockState = lockMode;

Additional resources on cursor locking in Unity and other cursor modes:
https://docs.unity3d.com/ScriptReference/CursorLockMode.html
https://docs.unity3d.com/ScriptReference/Cursor-visible.html
https://forum.unity.com/threads/disable-mouse-cursor-in-windows-during-play-mode.387416/

All Updated State Machines and Blend Trees

These are all of the State Machines and Blend Trees that I set up for my character in Mecanim: