public void updateFromState(NPCStateData n) { if (n.curHP != currentHP) { modifyNameplateHP(n.curHP); } }
public void updateFromState(NPCStateData data) { maxHealth = data.maxHP; currentHealth = data.curHP; targetPosition = data.position; targetRotation = data.rotation; State = (AI_State)data.state; UI_Nameplate.updateFromState(data); }
public void MoveTowardsLastSighting(NPCStateData stateData, float maxSpeed, float acceleration) { if (stateData.initializing == true) //code to be run on start of this state { stateData.npcBase.pathfinding.UpdatePath(stateData.npcBase.lastTargetSighting); } stateData.npcBase.pathfinding.UpdatePathOnInterval(stateData.npcBase.lastTargetSighting); stateData.npcBase.MoveAlongPath(maxSpeed, acceleration, false); }
public void world_updateNPCState(NPCStateData npc) { bool npcExists = NPCList.ContainsKey(npc.uniqueID); if (npcExists) { NPCList[npc.uniqueID].updateFromState(npc); } else { Debug.Log("Getting npc update for non-created NPC " + npc.uniqueID); } }
public void LookAround(NPCStateData stateData, float turnSpeed) { if (isLookingAtTargetAngle || stateData.initializing) { isLookingAtTargetAngle = false; targetAngle = UnityEngine.Random.Range(-90, 90) + stateData.npcBase.rb.rotation; pauseTime = UnityEngine.Random.Range(1, 3); pauseTimeCounter = 0; } pauseTimeCounter += Time.deltaTime; if (pauseTimeCounter >= pauseTime) { isLookingAtTargetAngle = stateData.npcBase.TurnTowardsAngle(targetAngle, turnSpeed); } }
public void TryToShoot(NPCStateData stateData, float delayBeforeFirstShot) { if (stateData.initializing == true) { timeSinceShootingStart = 0; } if (timeSinceShootingStart < delayBeforeFirstShot) { timeSinceShootingStart += Time.deltaTime; return; } if (rateOfFireCoutner > 1 / equippedGun.fireRate) { equippedGun.Shoot(); rateOfFireCoutner = 0; } }
public void PatrolPOIs(NPCStateData stateData, float maxSpeed, float acceleration, float turnSpeed) { if (stateData.initializing == true) //code to be run on start of this state { stateData.npcBase.pathfinding.PathToPOI(); timeWaitingAtPOI = UnityEngine.Random.Range(5, 10); } if (stateData.npcBase.pathfinding.distanceFromDestination < .25f) { timeWaitingAtPOICounter += Time.deltaTime; LookAround(stateData, turnSpeed); if (timeWaitingAtPOICounter >= timeWaitingAtPOI) { timeWaitingAtPOICounter = 0; timeWaitingAtPOI = UnityEngine.Random.Range(4, 10); stateData.npcBase.pathfinding.PathToPOI(); turningToFaceNewPath = true; } } else { if (turningToFaceNewPath == false) { stateData.npcBase.pathfinding.UpdatePathOnInterval(stateData.npcBase.pathfinding.pathDestination); stateData.npcBase.MoveAlongPath(maxSpeed, acceleration, true); stateData.npcBase.TurnTowardsAngle(stateData.npcBase.pathfinding.directionOfPathAngle, turnSpeed); } else { turningToFaceNewPath = !stateData.npcBase.TurnTowardsAngle(stateData.npcBase.pathfinding.directionOfPathAngle, turnSpeed / 2); } } }
public override void Deserialize(NetworkReader reader) { npcCount = reader.ReadInt32(); try { for (int i = 0; i < npcCount; i++) { NPCStateData npc = new NPCStateData(); npc.uniqueID = reader.ReadString(); npc.maxHP = reader.ReadSingle(); npc.curHP = reader.ReadSingle(); npc.maxEnergy = reader.ReadInt32(); npc.curEnergy = reader.ReadInt32(); npc.position = reader.ReadVector3(); npc.rotation = reader.ReadQuaternion(); npc.state = reader.ReadInt32(); Data.Add(npc); } } catch (System.Exception e) { Debug.Log(e.ToString()); } }
public void TurnToLastSighting(NPCStateData stateData, float turnSpeed) { stateData.npcBase.TurnTowardsPoint(stateData.npcBase.lastTargetSighting, turnSpeed); }
public void TurnToTarget(NPCStateData stateData, float turnSpeed) { stateData.npcBase.TurnTowardsPoint(stateData.npcBase.target.transform.position, turnSpeed); }