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_EditorClassIdentifier:
duration: 1
knockback: 1
stunDir: {x: 1000, y: 1000}
--- !u!1 &1070079036
GameObject:
m_ObjectHideFlags: 0

View File

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

View File

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

View File

@ -6,10 +6,19 @@ public class Stunning : MonoBehaviour
{
[SerializeField]
private float duration;
[SerializeField]
private bool knockback = true;
[SerializeField]
private Vector2 stunDir;
private void OnCollisionEnter(Collision other) {
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);
}
}
}
}