This is the script that controls the rotation of the camera around my character:
Lastly, this script controls the muzzle flash on my character's weapon, nothing fancy:

Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts
Saturday, March 23, 2019
All Updated Scripts--Movement Controller
This is the script that controls all of my character's movement in 3D space, translation, rotation, and forces being applied:
Friday, March 22, 2019
Demo Video Presentation
This is my presentation, showing off my project thus far, all of the state machines, briefly going over how I utilized Unity IK to create all of the functionality in my character controller in this project:
Part 01
Part 02
Part 03
Part 04
Part 05
Thursday, March 21, 2019
Aiming System--Unity IK
Aiming is almost completely implemented, but is acting strange because of how the character controller and look IK conflict when they control the character. Foot planting is taking a hiatus--for now.

Here is the updated IK Control script in the inspector, showing the parameters that have been added for controlling the look IK.

I will have to play with these in the script, or the character controller itself in order to resolve the issues.
Bug Fixing
So, I finished modifying the character controller code, reverting back to the original method I was using to control the character and camera, and the problem still persists. It appears to be controlling some of the IK handles in local space, and others in world space, which is very problematic.
I checked the documentation, and found that the function for moving an IK handle in space, "Animator.SetIKPosition" only works in world space by default, and there seems to be no way in the function to set it to local space. Even though I had parented the IK handles, they were still moving around in world space, making it impossible to control my character's hands' positions relative to the character. I noticed that the only IK handle that was cooperating was the left hand grab handle, located deep in the hierarchy, parented to the rifle. I have no idea why this is the case. If parenting causes IK handles to work in local space, then they should, no matter how dep in the character's hierarchy they are parented. I have parented all of the hand IK locator objects to the rifle in the character's right hand, which may produce better results anyway.
It did not achieve better results, because they are parented beneath the root bones in the hierarchy, and therefore, they don't aim directly to the center of the screen, but rather wherever the character is facing in the animation, which causes the character to aim to the right whenever I press the fire button, instead the center of the screen, which is not what I want.
I re-parented the right hand IK locator objects, which control the shooting, to the character rig, and somehow it is miraculously working. The character's hands and rifle now stay where they are supposed to be relative to the character's position/rotation in space. I have also successfully rewritten my IK Control script.
So, I am back where I was before with the hands instantaneously moving to the positions of the IK handles. The coroutine waitforseconds values are also the same as before, to try and fake smoothness. I tried multiple methods to translate the handles or to somehow blend the weights, none of them worked. So, now it is time to move on and build other features. As you may notice, I also have a test environment built using Sabre CSG, a free Unity Asset Store plugin that works similar to Unreal's built-in level builder tool, using boolean tools I will build on this test environment as needed and use it to rest my character's abilities. We will see more of it later:
Here is the new IK Control script:
I checked the documentation, and found that the function for moving an IK handle in space, "Animator.SetIKPosition" only works in world space by default, and there seems to be no way in the function to set it to local space. Even though I had parented the IK handles, they were still moving around in world space, making it impossible to control my character's hands' positions relative to the character. I noticed that the only IK handle that was cooperating was the left hand grab handle, located deep in the hierarchy, parented to the rifle. I have no idea why this is the case. If parenting causes IK handles to work in local space, then they should, no matter how dep in the character's hierarchy they are parented. I have parented all of the hand IK locator objects to the rifle in the character's right hand, which may produce better results anyway.
It did not achieve better results, because they are parented beneath the root bones in the hierarchy, and therefore, they don't aim directly to the center of the screen, but rather wherever the character is facing in the animation, which causes the character to aim to the right whenever I press the fire button, instead the center of the screen, which is not what I want.
I re-parented the right hand IK locator objects, which control the shooting, to the character rig, and somehow it is miraculously working. The character's hands and rifle now stay where they are supposed to be relative to the character's position/rotation in space. I have also successfully rewritten my IK Control script.
So, I am back where I was before with the hands instantaneously moving to the positions of the IK handles. The coroutine waitforseconds values are also the same as before, to try and fake smoothness. I tried multiple methods to translate the handles or to somehow blend the weights, none of them worked. So, now it is time to move on and build other features. As you may notice, I also have a test environment built using Sabre CSG, a free Unity Asset Store plugin that works similar to Unreal's built-in level builder tool, using boolean tools I will build on this test environment as needed and use it to rest my character's abilities. We will see more of it later:
Here is the new IK Control script:
Monday, March 18, 2019
Scripts: Cursor Lock State
I am now posting all of the scripts that I created for this project.
This one is almost entirely from Unity documentation, except that I modified it.
This one is almost entirely from Unity documentation, except that I modified it.
CursorLockState, simply just allows the cursor to be locked (constrained to center of screen, and turned invisible) and unlocked:
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:
The Movement Controller controls all of the movement (forces, translations, etc.) being applied to the character controller:
Subscribe to:
Posts (Atom)
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:

-
In Unity, you can lock the state of the cursor while in play mode, effectively turning the cursor invisible and constraining it to the cente...
-
Re-targeting and editing animations was going pretty well. It was nice to revisit Motion Builder. Everything was going fine i...