#2 test
This commit is contained in:
parent
62a6a29d9f
commit
9b46e4935b
@ -49,6 +49,7 @@ public partial class EnemyController : Pawn
|
||||
public NavMeshPath navMeshPath;
|
||||
public bool isKilling = false;
|
||||
[SerializeField] private bool canAttack = true;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Time.timeScale = 10;
|
||||
@ -93,6 +94,11 @@ public partial class EnemyController : Pawn
|
||||
_remainingDistance = controller.GetPathRemainingDistance();
|
||||
hasPath = controller.pathStatus != NavMeshPathStatus.PathComplete;
|
||||
|
||||
// if (controller.pathStatus == NavMeshPathStatus.PathComplete && !controller.pathPending && _target != null)
|
||||
// {
|
||||
// _target = null;
|
||||
// }
|
||||
|
||||
// Есть таргет?
|
||||
if (_target != null) // Да
|
||||
{
|
||||
@ -100,19 +106,13 @@ public partial class EnemyController : Pawn
|
||||
|
||||
float distance = Vector3.Distance(_target.transform.position, transform.position);
|
||||
|
||||
if (distance < aggressionDistance) // (_remainingDistance < aggressionDistance && _remainingDistance > 0)
|
||||
if (distance < aggressionDistance)
|
||||
{
|
||||
aimTarget.position = _target.position + _target.up * 1.2f;
|
||||
targetLayerWeight = 1f;
|
||||
|
||||
// Debug.Log(_remainingDistance);
|
||||
|
||||
// Если подошли к нему
|
||||
|
||||
if (distance < 1f)
|
||||
{
|
||||
// Debug.Log("da");
|
||||
|
||||
// _target.GetComponent<Interactions>().DropProp();
|
||||
if (canAttack && !isKilling)
|
||||
{
|
||||
RpcKillPlayer(_target);
|
||||
@ -129,15 +129,12 @@ public partial class EnemyController : Pawn
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (controller.GetPathRemainingDistance() <= 0f) // Нет mojet doiti
|
||||
targetLayerWeight = 0f;
|
||||
// Ищем ближайшего игрока
|
||||
foreach (var player in players)
|
||||
{
|
||||
float distance = Vector3.Distance(player.transform.position, transform.position);
|
||||
|
||||
// Debug.Log(CalculateNewPath(player.transform));
|
||||
|
||||
if (distance <= aggressionDistance && CalculateNewPath(player.transform)) // && _remainingDistance > 0
|
||||
{
|
||||
//if (_remainingDistance < aggressionDistance && controller.GetPathRemainingDistance() >= 0)
|
||||
|
@ -183,18 +183,24 @@ public class Interactions : NetworkBehaviour
|
||||
|
||||
if (hitInfo.transform != null)
|
||||
{
|
||||
// var player = hitInfo.transform.gameObject.GetComponent<Pawn>();
|
||||
var player = hitInfo.transform.gameObject.GetComponent<PersonController>();
|
||||
if (player != null)
|
||||
var pawn = hitInfo.transform.gameObject.GetComponent<Pawn>();
|
||||
|
||||
if (pawn != null)
|
||||
{
|
||||
CmdReductStamina(player);
|
||||
CmdAddDebuff(player);
|
||||
}
|
||||
var alien = hitInfo.transform.gameObject.GetComponent<EnemyController>();
|
||||
if (alien != null)
|
||||
{
|
||||
CmdHitAlien(alien);
|
||||
CmdHitPawn(pawn);
|
||||
}
|
||||
//
|
||||
// var player = hitInfo.transform.gameObject.GetComponent<PersonController>();
|
||||
// if (player != null)
|
||||
// {
|
||||
// CmdReductStamina(player);
|
||||
// CmdAddDebuff(player);
|
||||
// }
|
||||
// var alien = hitInfo.transform.gameObject.GetComponent<EnemyController>();
|
||||
// if (alien != null)
|
||||
// {
|
||||
// CmdHitAlien(alien);
|
||||
// }
|
||||
}
|
||||
|
||||
CmdShoot(hitInfo.point, Quaternion.LookRotation(hitInfo.normal));
|
||||
@ -213,28 +219,15 @@ public class Interactions : NetworkBehaviour
|
||||
}
|
||||
|
||||
[Command(requiresAuthority = false)]
|
||||
void CmdReductStamina(PersonController player)
|
||||
void CmdHitPawn(Pawn pawn)
|
||||
{
|
||||
RpcReductStamina(player);
|
||||
RpcHitPawn(pawn);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcReductStamina(PersonController player)
|
||||
void RpcHitPawn(Pawn pawn)
|
||||
{
|
||||
player.TakeDamage();
|
||||
player.InstantStaminaReduction(controller.shootDepletion * 0.7f);
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdHitAlien(EnemyController alien)
|
||||
{
|
||||
RpcHitAlien(alien);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcHitAlien(EnemyController alien)
|
||||
{
|
||||
alien.TakeDamage();
|
||||
pawn.TakeDamage();
|
||||
}
|
||||
|
||||
[Command]
|
||||
|
@ -1,157 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
|
||||
public class Interactions2 : NetworkBehaviour
|
||||
{
|
||||
[Header("Animations")]
|
||||
[SyncVar]
|
||||
private float takePropWeight = 0f;
|
||||
public Rig takePropRig;
|
||||
public Transform leftHandPos, rightHandPos;
|
||||
public GameObject _eyesObject;
|
||||
|
||||
[Header("Prop Prefs")]
|
||||
public GameObject propPrefab;
|
||||
private RaycastHit _hit;
|
||||
private Rigidbody _propRB;
|
||||
|
||||
[Header("Settings")]
|
||||
public float maxHitDistance = 6f;
|
||||
|
||||
[Header("GUI Staff")]
|
||||
public float hitDistance;
|
||||
public bool canInterract;
|
||||
|
||||
[Header("Links")]
|
||||
public StarterAssets.PersonController controller;
|
||||
|
||||
private PropGrab _grabbedProp;
|
||||
|
||||
void Update()
|
||||
{
|
||||
takePropRig.weight = takePropWeight;
|
||||
|
||||
if (!isLocalPlayer) return;
|
||||
|
||||
if (Physics.Raycast(_eyesObject.transform.position, _eyesObject.transform.TransformDirection(Vector3.forward), out _hit, maxHitDistance, LayerMask.NameToLayer("Player")))
|
||||
{
|
||||
Debug.DrawRay(_eyesObject.transform.position, _eyesObject.transform.TransformDirection(Vector3.forward) * hitDistance, Color.yellow);
|
||||
|
||||
canInterract = _hit.collider.tag == "Prop" || _hit.collider.tag == "Button" ? true : false;
|
||||
|
||||
if (Input.GetKey(KeyCode.E))
|
||||
{
|
||||
if (_hit.collider.tag == "Prop" && _propRB == null)
|
||||
{
|
||||
_propRB = _hit.collider.gameObject.GetComponent<Rigidbody>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hitDistance = _hit.distance > 0 ? _hit.distance : maxHitDistance;
|
||||
|
||||
if (Input.GetKey(KeyCode.E))
|
||||
{
|
||||
if (_propRB != null)
|
||||
{
|
||||
Vector3 target = _eyesObject.transform.position + _eyesObject.transform.forward;
|
||||
|
||||
if (isClient)
|
||||
{
|
||||
CmdPropGrab(target, _propRB.gameObject, _eyesObject.transform.rotation);
|
||||
SetPropRigWeight(1f);
|
||||
|
||||
CmdSetLayerMask(_propRB.gameObject, "Grab");
|
||||
}
|
||||
|
||||
PropBehaviour propBehaviour = _propRB.GetComponent<PropBehaviour>();
|
||||
setHands(leftHandPos, rightHandPos, propBehaviour);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isClient)
|
||||
{
|
||||
if (_propRB != null)
|
||||
{
|
||||
CmdSetLayerMask(_propRB.gameObject, "Default");
|
||||
}
|
||||
|
||||
SetPropRigWeight(0f);
|
||||
}
|
||||
_propRB = null;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Q))
|
||||
{
|
||||
if (isClient)
|
||||
{
|
||||
CmdSpawnObject(_eyesObject.transform.position + _eyesObject.transform.forward, _eyesObject.transform.rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Commands
|
||||
[Command]
|
||||
void CmdPropGrab(Vector3 target, GameObject prop, Quaternion dir)
|
||||
{
|
||||
RpcPropGrab(target, prop, dir);
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetLayerMask(GameObject gameObject, string str)
|
||||
{
|
||||
RpcSetLayerMask(gameObject, str);
|
||||
}
|
||||
|
||||
[Command]
|
||||
void SetPropRigWeight(float value)
|
||||
{
|
||||
takePropWeight = value;
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSpawnObject(Vector3 pos, Quaternion rot)
|
||||
{
|
||||
GameObject gameObject = Instantiate(propPrefab, pos, rot);
|
||||
NetworkServer.Spawn(gameObject);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Rpcs
|
||||
[ClientRpc]
|
||||
void RpcSetLayerMask(GameObject gameObject, string str)
|
||||
{
|
||||
gameObject.layer = LayerMask.NameToLayer(str);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcPropGrab(Vector3 target, GameObject prop, Quaternion dir)
|
||||
{
|
||||
Rigidbody propRB = prop.GetComponent<Rigidbody>();
|
||||
|
||||
Vector3 tarForce = target - propRB.transform.position;
|
||||
Vector3 force = (tarForce * 20f - propRB.velocity) * Time.deltaTime * 30f;
|
||||
|
||||
propRB.AddForce(force, ForceMode.Impulse);
|
||||
|
||||
propRB.MoveRotation(dir);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
void setHands(Transform lh, Transform rh, PropBehaviour pb)
|
||||
{
|
||||
lh.position = pb.leftHandPos.position;
|
||||
rh.position = pb.rightHandPos.position;
|
||||
|
||||
lh.rotation = pb.leftHandPos.rotation;
|
||||
rh.rotation = pb.rightHandPos.rotation;
|
||||
}
|
||||
#endregion
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d857e8e2df2a1143ab80b10cbb93b9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -122,7 +122,7 @@ namespace StarterAssets
|
||||
private void Start()
|
||||
{
|
||||
_controller = GetComponent<CharacterController>();
|
||||
this.OnDamage += TakeDamageAnimation;
|
||||
this.OnDamage += OnTakeDamage;
|
||||
|
||||
_gotEnergyClip = Resources.Load<AudioClip>("Audio/CharacterSounds/GetEnergy");
|
||||
|
||||
@ -348,9 +348,11 @@ namespace StarterAssets
|
||||
_parent = transf;
|
||||
}
|
||||
|
||||
void TakeDamageAnimation(Pawn self)
|
||||
// server
|
||||
void OnTakeDamage(Pawn self)
|
||||
{
|
||||
_animator.SetTrigger("damage");
|
||||
InstantStaminaReduction(shootDepletion * 0.7f);
|
||||
// Debug.Log(self.GetComponent<PersonController>().playerName);
|
||||
|
||||
// hitVFX.Stop();
|
||||
|
Loading…
x
Reference in New Issue
Block a user