/// <summary> /// Gets the member predicted position, using the group set up /// </summary> /// <returns>The member predicted position.</returns> /// <param name="member">Member.</param> public Vector3 getMemberPredictedPosition(GroupMemberMovement member) { int index = m_groupMembers.IndexOf(member); Transform[] formation = getCurrentFormation().Positions; if (index != -1) { //Get member position in formation and tranlate it into local space Vector3 currentMemberPos = formation [index].position; Vector3 localMemberPos = m_transform.InverseTransformPoint(currentMemberPos); //Calculate distance for prediction using the current speed and a the time interval used to update the positions float predictionDist = m_groupSpeed * m_positionUpdateInterval; predictionDist += localMemberPos.magnitude; //Calculate a path NavMeshHit prediction; m_navigationAgent.SamplePathPosition(m_navigationAgent.areaMask, predictionDist, out prediction); //Get the predicted position of the group leader and translate it into localspace Vector3 localPredictedPos = m_transform.InverseTransformPoint(prediction.position); //Add the predicted leader position and the local member position, add them, and translating it into a world space position //the result is the World Space predicted position of the group member return(m_transform.TransformPoint(localPredictedPos + localMemberPos)); } else { return(new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity)); } }
/// <summary> /// Gets the member position in the formation. /// </summary> /// <returns>The member position.</returns> /// <param name="member">Member.</param> public Vector3 getMemberPosition(GroupMemberMovement member) { int index = m_groupMembers.IndexOf(member); bool validMember = index == -1 && index < getCurrentFormation().Positions.Length; return(validMember ? new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity) : getCurrentFormation().Positions [index].position); }