Skip to content
Snippets Groups Projects
Commit 5fc5aa7d authored by MuhamadAjiW's avatar MuhamadAjiW
Browse files

feat: basic animation controller

parent 5f07b1af
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
...@@ -5,15 +6,14 @@ using UnityEngine; ...@@ -5,15 +6,14 @@ using UnityEngine;
public class Player : RigidObject{ public class Player : RigidObject{
private PlayerAnimationController animationController; private PlayerAnimationController animationController;
private PlayerMovementController movementController; private PlayerMovementController movementController;
private PlayerStateController stateController; public PlayerStateController stateController;
public PlayerStats stats; public PlayerStats stats;
public int State => stateController.state;
new void Start(){ new void Start(){
base.Start(); base.Start();
animationController = new PlayerAnimationController(this);
movementController = new PlayerMovementController(this);
stateController = new PlayerStateController(this); stateController = new PlayerStateController(this);
movementController = new PlayerMovementController(this);
animationController = new PlayerAnimationController(this);
stats = new PlayerStats(this); stats = new PlayerStats(this);
} }
......
using UnityEngine;
public class PlayerAnimationController{ public class PlayerAnimationController{
// Consts
private const string IDLE_TRIGGER = "idle_param";
private const string WALK_TRIGGER = "walk_param";
// Attributes // Attributes
private Player player; private Player player;
private PlayerStateController playerStateController;
private Transform modelTransform;
private Animator animator;
// Constructor // Constructor
public PlayerAnimationController(Player player){ public PlayerAnimationController(Player player){
this.player = player; this.player = player;
modelTransform = player.transform.Find("Model");
animator = modelTransform.GetComponent<Animator>();
player.stateController.OnStateChange += Animate;
}
public void Animate(){
Debug.Log("State changed " + player.stateController.state);
switch (player.stateController.state){
case PlayerState.IDLE:
animator.SetBool(IDLE_TRIGGER, true);
break;
case PlayerState.WALKING:
animator.SetBool(WALK_TRIGGER, true);
break;
}
} }
} }
...@@ -6,7 +6,7 @@ public class PlayerStats { ...@@ -6,7 +6,7 @@ public class PlayerStats {
public float jumpForce = 600; public float jumpForce = 600;
public float snapshotSpeed = 25; public float snapshotSpeed = 25;
public float MaxSpeed => player.State switch{ public float MaxSpeed => player.stateController.state switch{
PlayerState.WALKING => walkSpeed, PlayerState.WALKING => walkSpeed,
PlayerState.SPRINTING => sprintSpeed, PlayerState.SPRINTING => sprintSpeed,
PlayerState.JUMPING => snapshotSpeed, PlayerState.JUMPING => snapshotSpeed,
......
...@@ -6,7 +6,9 @@ public class RigidObject : MonoBehaviour { ...@@ -6,7 +6,9 @@ public class RigidObject : MonoBehaviour {
// Readonly by others // Readonly by others
private new Rigidbody rigidbody; private new Rigidbody rigidbody;
private new Collider collider; private new Collider collider;
private bool grounded;
//TODO: grounded automatic detection
private bool grounded = true;
public Rigidbody Rigidbody => rigidbody; public Rigidbody Rigidbody => rigidbody;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment