Welcome to GEMENTAR TOUR PUO V2 Development Documentation. Enjoy your stay!

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:prototyping [2022/08/12 01:18] – [NPC Agro prototype] adminwiki:prototyping [2022/08/15 23:52] (current) – [Prototyping Zombie Minigame] admin
Line 1: Line 1:
 ====== Prototyping Zombie Minigame ====== ====== Prototyping Zombie Minigame ======
  
 +{{ :wiki:image_2022-08-16_075049458.png?600 |}}
  
 +<file| Prototyping?>
 +This is the way I make function of models before I make it official.
 +</file>
 ====== Player Prototyping ====== ====== Player Prototyping ======
  
Line 14: Line 18:
 using System; using System;
 using Sirenix.OdinInspector; using Sirenix.OdinInspector;
 +using UnityEngine.Events;
 +using HighlightPlus;
  
 public class ZombiePlayerController : MonoBehaviour public class ZombiePlayerController : MonoBehaviour
Line 33: Line 39:
     [BoxGroup("Movement Fine Tune")]     [BoxGroup("Movement Fine Tune")]
     public float groundGravity = 1f;     public float groundGravity = 1f;
 +    [BoxGroup("Movement Fine Tune")]
 +    public float runStamina = 15f;
  
     [BoxGroup("Private Variable")]     [BoxGroup("Private Variable")]
Line 46: Line 54:
     [ShowInInspector]     [ShowInInspector]
     private float _righDirection;     private float _righDirection;
 +    [BoxGroup("Private Variable")]
 +    [ShowInInspector]
 +    private float _velocity;
 +    [BoxGroup("Private Variable")]
 +    [ShowInInspector]
 +    private float _storedRunStamina;
  
     private CharacterController _characterController;     private CharacterController _characterController;
 +    private ZombieHealth _zombieHealth;
 +    private HighlightEffect _highlight;
 +
 +    [HideInEditorMode]
 +    public UnityEvent<float> sendEventToUI;
 +
 +    [HideInEditorMode]
 +    public UnityEvent onPlayerDied;
  
     private void Awake()     private void Awake()
     {     {
         Initialization();         Initialization();
 +    }
 +
 +    private void Start()
 +    {
 +        _storedRunStamina = runStamina;
 +        _zombieHealth.sendEventOnMinusHealth.AddListener(ReceivedEventOnPlayerHit);
 +        SendEventToUI();
     }     }
  
Line 57: Line 86:
     {     {
         _characterController = this.GetComponent<CharacterController>();         _characterController = this.GetComponent<CharacterController>();
 +        _zombieHealth = this.GetComponent<ZombieHealth>();
 +        _highlight = this.GetComponent<HighlightEffect>();
     }     }
  
     private void Update()     private void Update()
     {     {
 +
 +        if (_zombieHealth.IsDead())
 +        {
 +            onPlayerDied.Invoke();
 +            return;
 +        }
 +
 +        _velocity = GetVelocity();
 +
         SetRightFowardDirection();         SetRightFowardDirection();
  
Line 94: Line 134:
         var desiredMoveDirection = (forward * verticalAxis + right * horizontalAxis).normalized * movementSpeed;         var desiredMoveDirection = (forward * verticalAxis + right * horizontalAxis).normalized * movementSpeed;
  
-        if(Input.GetKey(KeyCode.LeftShift))+        SprintController(); 
 + 
 +        if (Input.GetKey(KeyCode.LeftShift) && runStamina >= 0)
         {         {
             return desiredMoveDirection * movementSprintSpeed;             return desiredMoveDirection * movementSprintSpeed;
Line 101: Line 143:
         return desiredMoveDirection;         return desiredMoveDirection;
     }     }
 +
 +    private void SprintController()
 +    {
 +        SendEventToUI();
 +
 +        if(GetVelocity() > 5)
 +        {
 +            runStamina -= Time.deltaTime;
 +            return;
 +        }
 +
 +        if (runStamina < _storedRunStamina && GetVelocity() == 0) runStamina += Time.deltaTime;
 +    }    
  
     private float _jumpDuration = 0;     private float _jumpDuration = 0;
Line 159: Line 214:
     public float GetVelocity() => _characterController.velocity.magnitude;     public float GetVelocity() => _characterController.velocity.magnitude;
     #endregion     #endregion
-} 
  
-</code> +    #region EVENT 
- +    private void InitializeEvent()
- +
-<code CSharp | ZombiePlayerCharacterAnimationController Script> +
-using Animancer; +
-using System.Collections; +
-using System.Collections.Generic; +
-using UnityEngine; +
- +
-public class ZombiePlayerCharacterAnimationController : MonoBehaviour +
-{ +
-    [SerializeField] private AnimancerComponent _Animancer; +
-    [SerializeField] private ClipTransition _idle; +
-    [SerializeField] private ClipTransition _moveFoward; +
-    [SerializeField] private ClipTransition _moveBackward; +
-    [SerializeField] private ClipTransition _moveRight; +
-    [SerializeField] private ClipTransition _moveLeft; +
-    [SerializeField] private ClipTransition _runFoward; +
-    [SerializeField] private ClipTransition _runBackward; +
-    [SerializeField] private ClipTransition _runRight; +
-    [SerializeField] private ClipTransition _runLeft; +
- +
-    [SerializeField] private AudioSource _parentAudioSource; +
-    [SerializeField] private AudioClip _walkStepSoud; +
-    [SerializeField] private AudioClip _runStepSound; +
- +
-    private ZombiePlayerController playerController; +
- +
-    private void Start()+
     {     {
-        playerController = FindObjectOfType<ZombiePlayerController>(); +        if (sendEventToUI == null) sendEventToUI = new UnityEvent<float>(); 
-        _parentAudioSource = playerController.GetComponent<AudioSource>();+        SendEventToUI();
     }     }
  
-    private void Update()+    private void SendEventToUI()
     {     {
-        _Animancer.Play(_idle); +        sendEventToUI.Invoke(runStamina);
- +
-        MovementAnimationPlayByVelocity();+
     }     }
  
-    private void MovementAnimationPlayByVelocity()+    private void ReceivedEventOnPlayerHit()
     {     {
-        if (playerController.GetVelocity() > 4) // If player running +        _highlight.HitFX();
-        { +
-            PlayMovementByAnimation(_runFoward, _runBackward, _runRight, _runLeft, _runStepSound); +
- +
-        } +
-        else +
-        { +
-            PlayMovementByAnimation(_moveFoward, _moveBackward, _moveRight, _moveLeft, _walkStepSoud); +
-        } +
-    } +
- +
-    private void PlayMovementByAnimation(ClipTransition foward, ClipTransition backward, ClipTransition right, ClipTransition left, AudioClip stepSound) +
-    { +
-        if (playerController.GetFowardDiretion() > 1f) +
-        { +
-           var anim =  _Animancer.Play(foward); +
- +
-            anim.Events.Add(0.30f, () => _parentAudioSource.PlayOneShot(stepSound)); +
-            anim.Events.Add(0.80f, () => _parentAudioSource.PlayOneShot(stepSound)); +
-        } +
- +
-        if (playerController.GetFowardDiretion() < -1f) +
-        { +
-            var anim = _Animancer.Play(backward); +
- +
-            anim.Events.Add(0.30f, () => _parentAudioSource.PlayOneShot(stepSound)); +
-            anim.Events.Add(0.80f, () => _parentAudioSource.PlayOneShot(stepSound)); +
-        } +
- +
-        if (playerController.GetRightDirection() > 1f) +
-        { +
-            var anim = _Animancer.Play(right); +
- +
-            anim.Events.Add(0.30f, () => _parentAudioSource.PlayOneShot(stepSound)); +
-            anim.Events.Add(0.80f, () => _parentAudioSource.PlayOneShot(stepSound)); +
-        } +
- +
-        if (playerController.GetRightDirection() < -1f) +
-        { +
-            var anim = _Animancer.Play(left); +
- +
-            anim.Events.Add(0.30f, () => _parentAudioSource.PlayOneShot(stepSound)); +
-            anim.Events.Add(0.80f, () => _parentAudioSource.PlayOneShot(stepSound)); +
-        }+
     }     }
 +    # endregion
 } }
  
Line 352: Line 335:
  
 </code> </code>
 +
 <code CSharp | ZombieCameraController Script> <code CSharp | ZombieCameraController Script>
 using System.Collections; using System.Collections;
Line 450: Line 434:
     public float bulletSpeed = 25f;     public float bulletSpeed = 25f;
     public ParticleSystem bulletCollideParticle;     public ParticleSystem bulletCollideParticle;
- +    public float bulletDamage = 10; 
-    private RangeSensor _rangeSensor;+    public RangeSensor _rangeSensor;
     private MeshRenderer _meshRenderer;     private MeshRenderer _meshRenderer;
     private Pool _pool;     private Pool _pool;
Line 459: Line 443:
     private void Awake()     private void Awake()
     {     {
-        _rangeSensor = this.GetComponent<RangeSensor>(); 
         _meshRenderer = this.GetComponent<MeshRenderer>();         _meshRenderer = this.GetComponent<MeshRenderer>();
         _pool = FindObjectOfType<Pool>();         _pool = FindObjectOfType<Pool>();
Line 490: Line 473:
         canMove = false;         canMove = false;
         bulletCollideParticle.Play();         bulletCollideParticle.Play();
 +
 +        if(_rangeSensor.GetNearestDetection().TryGetComponent(out ZombieHealth zombieHealth))
 +        {
 +            zombieHealth.MinusHealth(bulletDamage);
 +        }
  
         StartCoroutine(DespawnGameObject(bulletCollideParticle.main.duration));         StartCoroutine(DespawnGameObject(bulletCollideParticle.main.duration));
Line 507: Line 495:
 } }
  
-</code> 
-====== NPC Prototyping ====== 
- 
-{{ :wiki:zombieprototypenpc.gif |}} 
- 
-<code CSharp | ZombieNpcMovingNashMeshController Script> 
-using Sirenix.OdinInspector; 
-using System.Collections; 
-using System.Collections.Generic; 
-using UnityEngine; 
-using UnityEngine.AI; 
- 
-public class ZombieNpcMovingNashMeshController : MonoBehaviour 
-{ 
-    [BoxGroup("Debug Value")] 
-    [SerializeField] private string d_tranfsormName; 
-    [BoxGroup("Debug Value")] 
-    [SerializeField] private float d_remainingDistance; 
-    [BoxGroup("Debug Value")] 
-    [SerializeField] private float d_velocity; 
- 
-    [BoxGroup("Movement Tweak")] [SerializeField] private float _walkSpeed = 1; 
-    [BoxGroup("Movement Tweak")] [SerializeField] private float _runSpeed = 3; 
- 
-    [SerializeField] private List<Transform> _checkPoint; 
-    private int checkPointIndex = 0; 
-    private int currentIndex = 0; 
- 
-    private NavMeshAgent _navMeshAgent; 
-    private ZombieAnimationController _zombieAnimationController; 
- 
-    [SerializeField] private Transform movePositionTransform; 
- 
-    private void Awake() 
-    { 
-        _navMeshAgent = GetComponent<NavMeshAgent>(); 
-        _zombieAnimationController = GetComponent<ZombieAnimationController>(); 
-        _navMeshAgent.updateRotation = false; 
-    } 
- 
-    private void Update() 
-    { 
-         
-        if (_navMeshAgent.remainingDistance <= _navMeshAgent.stoppingDistance) 
-        { 
-            
-            currentIndex = checkPointIndex == _checkPoint.Count - 1 ? checkPointIndex = 0 : checkPointIndex += 1; 
-             
-        } 
- 
-        MoveAgentToDestination(_checkPoint[currentIndex]); 
-    } 
- 
-    private void MoveAgentToDestination(Transform transform) 
-    { 
-        _navMeshAgent.destination = transform.position; 
- 
-        d_tranfsormName = transform.gameObject.name; 
-        d_remainingDistance = _navMeshAgent.remainingDistance; 
-        d_velocity = _navMeshAgent.velocity.magnitude; 
- 
-        if (_navMeshAgent.velocity.sqrMagnitude > Mathf.Epsilon) 
-        { 
-            this.transform.rotation = Quaternion.LookRotation(_navMeshAgent.velocity.normalized); 
-        } 
-    } 
- 
-    [Button] 
-    public void MakeCharacterWalk() 
-    { 
-        _navMeshAgent.speed = _walkSpeed; 
-    } 
- 
-    [Button] 
-    public void MakeCharacterRunning() 
-    { 
-        _navMeshAgent.speed = _runSpeed; 
-    } 
- 
-    [Button] 
-    public void MakeCharacterPunch() 
-    { 
-        _zombieAnimationController.PlayAction(_zombieAnimationController.attack); 
-    } 
-} 
  
 </code> </code>
- 
-<code CSharp | ZombieAnimationController Script> 
-using Animancer; 
-using Sirenix.OdinInspector; 
-using System.Collections; 
-using System.Collections.Generic; 
-using UnityEngine; 
-using UnityEngine.AI; 
- 
-public class ZombieAnimationController : MonoBehaviour 
-{ 
-    private AnimancerComponent _Animancer; 
-    [SerializeField] public ClipTransition idle; 
-    [SerializeField] public ClipTransition moveFoward; 
-    [SerializeField] public ClipTransition runFoward; 
-    [SerializeField] public ClipTransition attack; 
-    [SerializeField] private AvatarMask _baseBody; 
-    [SerializeField] private AvatarMask _upperBody; 
- 
-    private AnimancerLayer _baseLayer; 
-    private AnimancerLayer _upperBodyLayer; 
- 
-    //private CharacterController _characterController; 
-    private NavMeshAgent _navMeshAgent; 
- 
-    private void Awake() 
-    { 
-        Initialization(); 
- 
-        InitializationAnim(); 
-    } 
- 
-    private void Initialization() 
-    { 
-        //_characterController = GetComponent<CharacterController>(); 
-        _navMeshAgent = GetComponent<NavMeshAgent>(); 
-        _Animancer = GetComponentInChildren<AnimancerComponent>(); 
-    } 
- 
-    private void InitializationAnim() 
-    { 
-        _baseLayer = _Animancer.Layers[0]; 
-        _upperBodyLayer = _Animancer.Layers[1]; 
- 
-        _baseLayer.SetMask(_baseBody); 
-        _upperBodyLayer.SetMask(_upperBody); 
-        attack.Events.OnEnd = OnActionEnd; 
-    } 
- 
-    private void Update() 
-    { 
-        //if(_characterController.velocity.magnitude > 1f) 
-        if (_navMeshAgent.velocity.magnitude > 1f) 
-        { 
-            _baseLayer.Play(moveFoward, 1f); 
-        } 
- 
-        //if (_characterController.velocity.magnitude > 2f) 
-        if(_navMeshAgent.velocity.magnitude > 2f) 
-        { 
-            _baseLayer.Play(runFoward, 1f); 
-        } 
-    } 
- 
-    bool _canBePlayed = true; 
-    public void PlayAction(ClipTransition clip) 
-    { 
-        if (!_canBePlayed) return; 
- 
-        _upperBodyLayer.Play(clip); 
- 
-        StartCoroutine(PlayActionDelay(clip.Clip.length)); 
-    } 
- 
-    private IEnumerator PlayActionDelay(float length) 
-    { 
-        _canBePlayed = false; 
-        yield return new WaitForSeconds(length); 
-        _canBePlayed = true; 
-    } 
- 
-    private void OnActionEnd() 
-    { 
-        _upperBodyLayer.StartFade(0, 1f); 
-    } 
-} 
- 
-</code> 
- 
-====== NPC Agro prototype ====== 
- 
-{{ :wiki:image_2022-08-12_084053997.png?600 |}} 
- 
- 
-<file | Agro >  
-There's basically three layers of detection 
-- outer layer when zombie heard shoots they will go agro, and this layer player need to escape from it to stop the agro. 
-- first inner when player move close to zombie. 
-- nearest layer for zombie detect when can it hit player. 
-</file> 
- 
-====== NavMesh Agent AI ====== 
- 
-{{ :wiki:zombieprototypenpc2.gif |}} 
  

QR Code
QR Code wiki:prototyping (generated for current page)
Hello World!
DokuWiki with monobook... rules!