void UpdateMovement() { if (m_moveMessage.Count == 0) { m_desiredSpeed = 0; return; } // Adjust the forward speed towards the desired speed. m_desiredSpeed = maxSpeed; m_currentSpeed = Mathf.MoveTowards(m_currentSpeed, m_desiredSpeed, acceleration * Time.deltaTime); MoveMessage step = m_moveMessage.Peek(); Vector3 position = step.position; float distance = Vector3.Distance(transform.position, position); if (distance > 3.0f) { // if the distance between current position and next position are not close transform.LookAt(position); } float t = (distance < float.Epsilon) ? 1.0f : (m_currentSpeed + 0.1f) * Time.deltaTime / distance; // cannot greater than 1 t = t > 1.0f ? 1.0f : t; position = Vector3.Lerp(transform.position, position, t); if (step.message == MsgType.MOVE) { // prject this position on to ground Vector3 hit = HitGround(position); if ((hit - transform.position).sqrMagnitude > 0.1f) { // not too close, prevent dead loop position = hit; } } DebugUtil.DrawLine(transform.position, position, Color.red); transform.position = position; // send to server to revise the sprite position PositionRevise(); if (step.message == MsgType.END_BACK || step.message == MsgType.BEGIN_BACK) { // end chase enemy m_target = null; } if (Mathf.Abs(1.0f - t) < 0.001) { // is nearly begin or end position m_receiver.OnReceiveMessage(step.message, this, step.position); m_moveMessage.Dequeue(); if (step.message == MsgType.END_CHASE) { DebugUtil.DrawLine(transform.position, transform.position + Vector3.up, Color.green); } } }
private void OnRecvHit(IChannel channel, Message message) { SHit msg = message as SHit; NetworkEntity target = networkEntities[msg.targetId]; NetworkEntity source = null; if (msg.sourceId != 0) { source = networkEntities[msg.sourceId]; } if (source.behavior == null) { return; } ICreatureBehavior srcBehavior = source == null ? null : source.behavior; ICreatureBehavior tarBehavior = target.behavior; tarBehavior.BeHit(msg.decHP, srcBehavior); if (target.entityId == World.Instance.selfId && source.entityType == EntityType.PLAYER) { World.Instance.setDeathId(source.entityId); } else { World.Instance.setDeathId(-1); } }
public void BeginChase(Vector3 position, ICreatureBehavior target) { m_target = target; m_moveMessage.Clear(); m_desiredSpeed = maxSpeed; MoveMessage step; step.position = position; step.message = MsgType.BEGIN_CHASE; m_moveMessage.Enqueue(step); }
public void BeHit(int decHP, ICreatureBehavior source) { var msg = new Damageable.DamageMessage() { amount = decHP, damager = this, direction = Vector3.up, stopCamera = false }; m_damageable.ApplyDamage(msg); }
public void BeHit(int decHP, ICreatureBehavior source) { m_Animator.SetTrigger(m_HashHurt); // Find the direction of the damage. Vector3 forward = source.GetTransform().position - transform.position; forward.y = 0f; Vector3 localHurt = transform.InverseTransformDirection(forward); // Set the HurtFromX and HurtFromY parameters of the animator based on the direction of the damage. m_Animator.SetFloat(m_HashHurtFromX, localHurt.x); m_Animator.SetFloat(m_HashHurtFromY, localHurt.z); var msg = new Damageable.DamageMessage() { amount = decHP, damager = this, direction = Vector3.up, stopCamera = false }; m_Damageable.ApplyDamage(msg); if (IsMine) { // Shake the camera. CameraShake.Shake(CameraShake.k_PlayerHitShakeAmount, CameraShake.k_PlayerHitShakeTime); // Play an audio clip of being hurt. if (hurtAudioPlayer != null) { hurtAudioPlayer.PlayRandomClip(); } if (m_healthUI != null) { m_healthUI.ChangeHitPointUI(m_Damageable); } } }
private void OnRecvHit(IChannel channel, Message message) { SHit msg = message as SHit; NetworkEntity target = networkEntities[msg.targetId]; NetworkEntity source = null; if (msg.sourceId != 0) { source = networkEntities[msg.sourceId]; } if (source.behavior == null) { return; } ICreatureBehavior srcBehavior = source == null ? null : source.behavior; ICreatureBehavior tarBehavior = target.behavior; tarBehavior.BeHit(msg.decHP, srcBehavior); }
private void OnRecvHit(IChannel channel, Message message) { SHit msg = message as SHit; UnityEngine.Debug.Log(string.Format("{0} hit {1} hp:{2}", msg.sourceId, msg.targetId, msg.decHP)); NetworkEntity target = networkEntities[msg.targetId]; NetworkEntity source = null; if (msg.sourceId != 0) { source = networkEntities[msg.sourceId]; source.gameObject.SetActive(true); } if (source.behavior == null) { return; } ICreatureBehavior srcBehavior = source == null ? null : source.behavior; ICreatureBehavior tarBehavior = target.behavior; tarBehavior.BeHit(msg.decHP, srcBehavior); }
public void Attack(ICreatureBehavior target) { m_attacking = true; }
public void Attack(ICreatureBehavior target) { m_receiver.OnReceiveMessage(MsgType.ATTACK, this, target); }