mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
Player walk animations
-Added walk animation -Added strafe animation -Added animation blending for strafe and walk -Added method that controls animation parameters based on movement speed -smol canvas fix
This commit is contained in:
@@ -10,10 +10,11 @@ public class PlayerController : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private ProcedualAnimationController procedualAnimationController;
|
||||
[Header("Movement")]
|
||||
[SerializeField] private float walkSpeed = 6.0f;
|
||||
[SerializeField] private float sprintSpeed = 10.0f;
|
||||
[SerializeField] private float walkSpeed = 5.0f;
|
||||
[SerializeField] private float sprintSpeed = 7.0f;
|
||||
[SerializeField] private float aimWalkSpeed = 3.0f;
|
||||
[SerializeField] private float fallDamageSpeed = 10.0f;
|
||||
|
||||
|
||||
[SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.001f;
|
||||
[SerializeField] float gravity = -10.0f;
|
||||
@@ -31,13 +32,14 @@ public class PlayerController : NetworkBehaviour
|
||||
|
||||
public bool isGrounded;
|
||||
public bool isSprinting;
|
||||
private float movementSpeed;
|
||||
public float currentMaxSpeed = 5.0f;
|
||||
private float velocityY = 0.0f;
|
||||
private CharacterController controller;
|
||||
|
||||
private Vector3 currentDir = Vector3.zero;
|
||||
public Vector3 currentDir = Vector3.zero;
|
||||
private Vector3 currentDirVelocity = Vector3.zero;
|
||||
public Vector3 velocity = Vector3.zero;
|
||||
public Vector3 localVelocity = Vector3.zero;
|
||||
private Vector3 refVelocity = Vector3.zero;
|
||||
|
||||
|
||||
@@ -108,14 +110,14 @@ public class PlayerController : NetworkBehaviour
|
||||
|
||||
if (Input.GetAxisRaw("Sprint") > 0 && isGrounded && !procedualAnimationController.isAiming)
|
||||
{
|
||||
movementSpeed = sprintSpeed;
|
||||
currentMaxSpeed = sprintSpeed;
|
||||
isSprinting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if(procedualAnimationController.isAiming) movementSpeed = aimWalkSpeed;
|
||||
else movementSpeed = walkSpeed;
|
||||
if(procedualAnimationController.isAiming) currentMaxSpeed = aimWalkSpeed;
|
||||
else currentMaxSpeed = walkSpeed;
|
||||
isSprinting = false;
|
||||
|
||||
}
|
||||
@@ -159,8 +161,9 @@ public class PlayerController : NetworkBehaviour
|
||||
moveDirection = new Vector3(moveDirection.x, 0, moveDirection.z);
|
||||
currentDir = moveDirection;
|
||||
}
|
||||
|
||||
velocity = Vector3.SmoothDamp(velocity, currentDir * movementSpeed + new Vector3(0, velocityY, 0),ref refVelocity,0.01f);
|
||||
Debug.Log(currentMaxSpeed);
|
||||
velocity = Vector3.SmoothDamp(velocity, currentDir * currentMaxSpeed + new Vector3(0, velocityY, 0),ref refVelocity,moveSmoothTime);
|
||||
localVelocity = transform.InverseTransformDirection(velocity);
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
//transform.position += velocity * Time.deltaTime;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ public class ProcedualAnimationController : NetworkBehaviour
|
||||
[SerializeField] float maxRecoil = 0.1f;
|
||||
|
||||
private Animator gunAnimator;
|
||||
[SerializeField] private Animator playerAnimator;
|
||||
|
||||
Vector3 startPos, startRot;
|
||||
float recoilOffset = 0f;
|
||||
@@ -93,7 +94,11 @@ public class ProcedualAnimationController : NetworkBehaviour
|
||||
Vector3[] positionMod = new Vector3[3];
|
||||
public Quaternion[] rotationMod = new Quaternion[3];
|
||||
|
||||
|
||||
public void walkAnimation()
|
||||
{
|
||||
playerAnimator.SetFloat("x", playerController.localVelocity.x / playerController.currentMaxSpeed);
|
||||
playerAnimator.SetFloat("y", playerController.localVelocity.z / playerController.currentMaxSpeed);
|
||||
}
|
||||
public void OnSwitchWeapon(GameObject currentWeapon)
|
||||
{
|
||||
if (isLocalPlayer) {
|
||||
@@ -135,6 +140,8 @@ public class ProcedualAnimationController : NetworkBehaviour
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
walkAnimation();
|
||||
|
||||
CmdAim(Input.GetButton("Aim"));
|
||||
}
|
||||
/*-----Aiming-----*/
|
||||
|
||||
Reference in New Issue
Block a user