mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-03-22 01:34:22 -05:00
86 lines
3.1 KiB
C#
86 lines
3.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using MLAPI;
|
|
using UnityEngine;
|
|
|
|
public class KickController : NetworkBehaviour
|
|
{
|
|
//Important, may want to change blink code to only work for trigger collider
|
|
// so that the player doesn't teleport to their leg
|
|
private GameObject leg;
|
|
private bool isKicking = false;
|
|
//slightly bad practice, when merging find a better work around
|
|
private bool isDiveKicking = false;
|
|
private CharacterController characterController;
|
|
public PlayerMovement pMove;
|
|
public PlayerStats pStats;
|
|
|
|
void Start(){
|
|
pStats = GetComponent<PlayerStats>();
|
|
pMove = GetComponent<PlayerMovement>();
|
|
characterController = this.gameObject.GetComponent<CharacterController>();
|
|
leg = transform.GetChild(0).gameObject;
|
|
leg.SetActive(false);
|
|
}
|
|
|
|
void Update(){
|
|
Kick();
|
|
}
|
|
|
|
void Kick(){
|
|
//Note: when we merge this into PlayerMovement, we may want to change isgrounded to our
|
|
//custom is grounded
|
|
//If F is pressed or gamepad right trigger is pulled
|
|
if ((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false && pMove.isGrounded == false && pMove.isSliding==false)
|
|
{
|
|
Debug.Log("dive");
|
|
// if kicking in air, kick until grounded (maybe add some foward momentum if needeD)
|
|
isKicking = true;
|
|
isDiveKicking = true;
|
|
leg.SetActive(true);
|
|
}
|
|
//otherwise do ground kick for .3 seconds
|
|
else if ((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false && pMove.isSliding==false){
|
|
StartCoroutine(Kicking(.3f));
|
|
}
|
|
|
|
//once dive kick touches ground, set back to normal state
|
|
if (pMove.isGrounded == true && isDiveKicking == true)
|
|
{
|
|
isDiveKicking = false;
|
|
isKicking = false;
|
|
leg.SetActive(false);
|
|
|
|
}
|
|
}
|
|
|
|
private IEnumerator Kicking(float waitTime){
|
|
isKicking = true;
|
|
leg.SetActive(true);
|
|
yield return new WaitForSeconds(waitTime);
|
|
isKicking = false;
|
|
leg.GetComponent<Collider>().isTrigger = false;
|
|
leg.SetActive(false);
|
|
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
if (!IsLocalPlayer) { return; }
|
|
Collider myCollider = collision.contacts[0].thisCollider;
|
|
if (collision.transform.CompareTag("kickable") && myCollider == leg.GetComponent<Collider>()){
|
|
if(collision.gameObject.GetComponent<Rigidbody>().isKinematic == true){
|
|
collision.gameObject.GetComponent<Rigidbody>().isKinematic = false;
|
|
}
|
|
Vector3 direction = this.transform.forward;
|
|
Debug.Log(direction);
|
|
collision.rigidbody.AddForce(direction * pStats.KickPow, ForceMode.Impulse);
|
|
leg.GetComponent<Collider>().isTrigger = true;
|
|
}
|
|
if (collision.transform.CompareTag("destroyable") && myCollider == leg.GetComponent<Collider>()){
|
|
collision.transform.gameObject.GetComponent<BreakableBlock>().damage(pStats.KickPow);
|
|
}
|
|
}
|
|
|
|
}
|