lose Mom on wall and kick renetworked

This commit is contained in:
Melbyj1125
2022-02-23 13:55:30 -06:00
parent b9a573a97d
commit d9629ec555
8 changed files with 92 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAPI;
using MLAPI.Messaging;
public class OffenseStateManager : NetworkBehaviour
{
@@ -104,16 +105,38 @@ public class OffenseStateManager : NetworkBehaviour
{
if (!IsLocalPlayer) { return; }
Collider myCollider = collision.contacts[0].thisCollider;
if (collision.transform.CompareTag("kickable") && myCollider == legHitbox.GetComponent<Collider>()){
if(collision.gameObject.GetComponent<Rigidbody>().isKinematic == true){
collision.gameObject.GetComponent<Rigidbody>().isKinematic = false;
}
// Kickable items must be handled through the server since they need to modify the NetworkTransform
if (collision.transform.CompareTag("kickable") && myCollider == legHitbox.GetComponent<Collider>()) {
Vector3 direction = this.transform.forward;
Debug.Log(direction);
collision.rigidbody.AddForce(direction * pStats.KickPow, ForceMode.Impulse);
//ulong prefabHash = collision.gameObject.GetComponent<NetworkObject>().PrefabHash;
ulong netObjID = collision.gameObject.GetComponent<NetworkObject>().NetworkObjectId;
ApplyKickServerRPC(direction, netObjID);
}
if (collision.transform.CompareTag("destroyable") && myCollider == legHitbox.GetComponent<Collider>()){
collision.transform.gameObject.GetComponent<BreakableBlock>().damage(pStats.KickPow);
}
}
[ServerRpc(RequireOwnership = false)]
private void ApplyKickServerRPC(Vector3 direction, ulong netObjId) {
GameObject[] kickables = GameObject.FindGameObjectsWithTag("kickable");
foreach (GameObject kickedItem in kickables) {
// First check to make sure this is the item we kicked
if (kickedItem.GetComponent<NetworkObject>() != null && kickedItem.GetComponent<NetworkObject>().NetworkObjectId == netObjId) {
// First turn off kinematic
if (kickedItem.gameObject.GetComponent<Rigidbody>().isKinematic == true) {
kickedItem.gameObject.GetComponent<Rigidbody>().isKinematic = false;
}
// Then apply the force
kickedItem.gameObject.GetComponent<Rigidbody>().AddForce(direction * pStats.KickPow, ForceMode.Impulse);
// Then return since we only kicked one item and don't need to check the remainder of the items
return;
}
}
}
}