Example #1
0
 public override MoveLookTarget GetNextPathWaypoint(MoveLookTarget aPathTarget, bool aAllow3DMovement, bool aAllowOffGraphMovement, MoveLookTarget aCachedMoveLookTarget = null)
 {
     mlt = base.GetNextPathWaypoint(aPathTarget, aAllow3DMovement, aAllowOffGraphMovement, aCachedMoveLookTarget);
     //Debug.Log("Called GetNextPathWaypoint");
     
     return mlt;
 }
 public override ActionResult Execute(RAIN.Core.AI ai)
 {
     GameObject loc = ai.WorkingMemory.GetItem<GameObject>("varHero");
     MoveLookTarget newTarget = new MoveLookTarget();
     newTarget.VectorTarget = new Vector3(loc.transform.position.x, 0, loc.transform.position.z);
     newTarget.CloseEnoughDistance = ai.Motor.CloseEnoughDistance;
     ai.WorkingMemory.SetItem(MoveTarget.VariableName, newTarget);
     return ActionResult.SUCCESS;
 }
Example #3
0
    public override ActionResult Execute(AI ai)
    {
        //get player
        GameObject player = ai.WorkingMemory.GetItem<GameObject>("posPlayer");

        var playerPosition = player.transform.position;
        //Debug.Log("p: " + playerPosition);

        //get enemy position
        var enemyPosition = new Vector3(ai.Kinematic.Position.x, ai.Kinematic.Position.y, ai.Kinematic.Position.z);
        //Debug.Log("e: " + enemyPosition);

        //computes the different between both positions
        var difference = (enemyPosition - playerPosition);
        //normalizes the vector
        //difference.Normalize();
        //Debug.Log("dif: " + difference);

        //checks how close enemy and player are
        var dist = Vector3.Distance(playerPosition, enemyPosition);
        var mag = remap(dist, 0, 11, 11, 0);
        difference *= (mag/3);
        //Debug.Log("old mag: " + dist + "  new mag: " + mag);

        //computes the new escape point
        var result = (enemyPosition+difference);
        //Debug.Log("new scape point: " + result);
        result.y = playerPosition.y;

        //update the scapePoint
        var newPosition = new MoveLookTarget();
        //result.VectorTarget = new Vector3(200,1,215);
        newPosition.VectorTarget = result;
        ai.WorkingMemory.SetItem<MoveLookTarget>("escapePoint", newPosition);
        //ai.Motor.MoveTo(result);

        return ActionResult.SUCCESS;
    }
        public override bool IsAt(MoveLookTarget aPosition)
        {
            var fMaxCloseEnoughDistance = Mathf.Max(aPosition.CloseEnoughDistance, AI.Motor.CloseEnoughDistance);

            bool flag = false;

            if (AI.Motor.Allow3DMovement)
            {
                var vector2 = AI.Kinematic.Position - aPosition.Position;

                if (vector2.magnitude <= fMaxCloseEnoughDistance)
                {
                    flag = true;
                }
            }
            else
            {
                var position = aPosition.Position;
                position.y = AI.Kinematic.Position.y;
                var vector3 = AI.Kinematic.Position - position;

                if (vector3.magnitude <= fMaxCloseEnoughDistance)
                {
                    flag = true;
                }
            }

            return flag;
        }
 public override bool GetPathToMoveTarget(MoveLookTarget aPathTarget, bool aAllowOffGraphMovement, out RAINPath aPath)
 {
     throw new NotImplementedException();
 }
 public override MoveLookTarget GetNextPathWaypoint(MoveLookTarget aPathTarget, bool aAllow3DMovement, bool aAllowOffGraphMovement, MoveLookTarget aCachedMoveLookTarget = null)
 {
     throw new NotImplementedException();
 }
        public override MoveLookTarget GetNextPathWaypoint(bool allow3DMovement, bool allowOffGraphMovement, MoveLookTarget moveLookTarget)
        {
            if (moveLookTarget == null)
            {
                moveLookTarget = new RAIN.Motion.MoveLookTarget();
            }

            if ((base.pathTarget == null) || !base.pathTarget.IsValid)
            {
                moveLookTarget.TargetType = MoveLookTarget.MoveLookTargetType.None;
                return moveLookTarget;
            }

            if (_aStarAIPath.canMove)
            {
                _aStarAIPath.TargetPosition = wp.position;

                moveLookTarget.VectorTarget = _aStarAIPath.TargetPoint;
            }

            return moveLookTarget;
        }
Example #8
0
    public override bool GetPathToMoveTarget(MoveLookTarget aPathTarget, bool allowOffGraphMovement, out RAINPath path)
    {
        //Debug.Log("Called GetPathToMoveTarget");
        var result = base.GetPathToMoveTarget(aPathTarget, allowOffGraphMovement, out path);

        for (int i = 0; i < path.PathPoints.Count; i++)
        {
            var p = path.PathPoints[i];
            path.PathPoints[i] = new Vector3(Mathf.Round(p.x), 0, Mathf.Round(p.z));
        }

        if (path.PathNodes.Count == 2)
        {
            return result;
        }

        for (int i = 0; i < path.PathNodes.Count - 1; i++)
        {
            if (path.PathPoints[i] == path.PathPoints[i + 1])
            {
                path.RemovePathNode(i);
                i--;
            }
        }

        bool sameX = false;
        bool sameZ = false;
        for (int i = 0; i < path.PathNodes.Count - 1; i++)
        {
            //if (Mathf.Approximately(path.PathPoints[i].x, AI.Body.transform.position.x) &&
            //    Mathf.Approximately(path.PathPoints[i].z, AI.Body.transform.position.z))
            //{
                //path.RemovePathNode(i);
                //i--;
            //}
            if (sameX)
            {
                if (path.PathPoints[i].x == path.PathPoints[i + 1].x)
                {
                    path.RemovePathNode(i);
                    i--;
                }
                else
                {
                    sameX = false;
                }
            }
            else if (sameZ)
            {
                if (path.PathPoints[i].z == path.PathPoints[i + 1].z)
                {
                    path.RemovePathNode(i);
                    i--;
                }
                else
                {
                    sameZ = false;
                }
            }
            if (!sameX && !sameZ)
            {
                if (path.PathPoints[i].x == path.PathPoints[i + 1].x)
                {
                    sameX = true;
                }
                else if (path.PathPoints[i].z == path.PathPoints[i + 1].z)
                {
                    sameZ = true;
                }
            }
            
        }
        if (Mathf.Approximately(path.PathPoints[0].x, path.PathPoints[path.PathPoints.Count - 1].x) ||
            Mathf.Approximately(path.PathPoints[0].z, path.PathPoints[path.PathPoints.Count - 1].z))
        {
            for (int i = 1; i < path.PathPoints.Count - 1; i++)
            {
                path.RemovePathNode(i);
                --i;
            }
        }


        return result;
    }
Example #9
0
 public override bool IsAt(MoveLookTarget aTarget)
 {
     //Debug.Log("Called IsAt");
     return base.IsAt(aTarget);
 }
Example #10
0
 public override bool IsAt(MoveLookTarget aTarget)
 {
     return IsAt(aTarget.Position);
 }
Example #11
0
 public override bool IsFacing(MoveLookTarget aTarget)
 {
     // Too tired to do this
     return true;
 }