Stuns can knockback player in chosen dir

This commit is contained in:
Soulaha Balde 2022-10-21 22:23:21 -04:00
parent fd9cee838c
commit beafdf2078
4 changed files with 18 additions and 3 deletions

View File

@ -1555,6 +1555,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
duration: 1 duration: 1
knockback: 1
stunDir: {x: 1000, y: 1000}
--- !u!1 &1070079036 --- !u!1 &1070079036
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -159,7 +159,6 @@ public class GrappleHook : MonoBehaviour
private void UnStun(){ private void UnStun(){
isStunned = false; isStunned = false;
Debug.Log("unstunned");
} }
#endregion #endregion
@ -168,7 +167,6 @@ public class GrappleHook : MonoBehaviour
public void Stun(float duration){ public void Stun(float duration){
isStunned = true; isStunned = true;
EndGrapple(); EndGrapple();
Debug.Log("Stunned");
Invoke("UnStun", duration); Invoke("UnStun", duration);
} }
#endregion #endregion

View File

@ -6,9 +6,11 @@ public class PlayerController : MonoBehaviour
{ {
private GrappleHook grappleScript; private GrappleHook grappleScript;
private CharacterMovement movementScript; private CharacterMovement movementScript;
private Rigidbody rb;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
rb = GetComponent<Rigidbody>();
grappleScript = GetComponent<GrappleHook>(); grappleScript = GetComponent<GrappleHook>();
movementScript = GetComponent<CharacterMovement>(); movementScript = GetComponent<CharacterMovement>();
} }
@ -23,4 +25,8 @@ public class PlayerController : MonoBehaviour
grappleScript.Stun(duration); grappleScript.Stun(duration);
movementScript.Stun(duration); movementScript.Stun(duration);
} }
public void Knockback(Vector2 dir){
rb.AddForce(dir);
}
} }

View File

@ -6,10 +6,19 @@ public class Stunning : MonoBehaviour
{ {
[SerializeField] [SerializeField]
private float duration; private float duration;
[SerializeField]
private bool knockback = true;
[SerializeField]
private Vector2 stunDir;
private void OnCollisionEnter(Collision other) { private void OnCollisionEnter(Collision other) {
if(other.gameObject.tag.Equals("Player")){//Collided w/ player, stun him if(other.gameObject.tag.Equals("Player")){//Collided w/ player, stun him
other.gameObject.GetComponent<PlayerController>().Stun(duration); PlayerController player = other.gameObject.GetComponent<PlayerController>();
player.Stun(duration);
if(knockback){
player.Knockback(stunDir);
}
} }
} }
} }