BVB Source Codes

CRYENGINE Show MovementBlock_FollowPath.cpp Source code

Return Download CRYENGINE: download MovementBlock_FollowPath.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "MovementBlock_FollowPath.h"
  5. #include <CryAISystem/MovementUpdateContext.h>
  6. #include "MovementActor.h"
  7. #include "PipeUser.h"
  8. #include "Cover/CoverSystem.h"
  9.  
  10. namespace Movement
  11. {
  12. namespace MovementBlocks
  13. {
  14.  
  15. FollowPath::FollowPath(
  16.   const CNavPath& path,
  17.   const float endDistance,
  18.   const MovementStyle& style,
  19.   const bool endsInCover)
  20.         : m_path(path)
  21.         , m_finishBlockEndDistance(endDistance)
  22.         , m_accumulatedPathFollowerFailureTime(0.0f)
  23.         , m_style(style)
  24.         , m_endsInCover(endsInCover)
  25. {
  26. }
  27.  
  28. void FollowPath::Begin(IMovementActor& actor)
  29. {
  30.         m_accumulatedPathFollowerFailureTime = 0.0f;
  31.         m_stuckDetector.Reset();
  32.         Movement::Helpers::BeginPathFollowing(actor, m_style, m_path);
  33.  
  34.         if (m_style.ShouldGlanceInMovementDirection())
  35.         {
  36.                 // Offset the look timer so that we don't start running the
  37.                 // looking immediately. It effectively means that we delay
  38.                 // the looking code from kicking in for X seconds.
  39.                 // It's good because the agent normally needs some time to start
  40.                 // movement transitions etc.
  41.                 static float lookTimeOffset = -1.5f;
  42.                 actor.GetAdapter().SetLookTimeOffset(lookTimeOffset);
  43.                 m_lookTarget = actor.GetAdapter().CreateLookTarget();
  44.         }
  45. }
  46.  
  47. void FollowPath::End(IMovementActor& actor)
  48. {
  49.         m_lookTarget.reset();
  50. }
  51.  
  52. Movement::Block::Status FollowPath::Update(const MovementUpdateContext& context)
  53. {
  54.         context.actor.GetAdapter().ResetMovementContext();
  55.  
  56.         if (m_endsInCover)
  57.                 context.actor.GetAdapter().UpdateCoverLocations();
  58.  
  59.         PathFollowResult result;
  60.         const bool targetReachable = Movement::Helpers::UpdatePathFollowing(result, context, m_style);
  61.  
  62.         const Vec3 physicsPosition = context.actor.GetAdapter().GetPhysicsPosition();
  63.         const float pathDistanceToEnd = context.pathFollower.GetDistToEnd(&physicsPosition);
  64.  
  65.         context.actor.GetAdapter().UpdateLooking(context.updateTime, m_lookTarget, targetReachable, pathDistanceToEnd, result.followTargetPos, m_style);
  66.  
  67.         m_stuckDetector.Update(context);
  68.  
  69.         if (m_stuckDetector.IsAgentStuck())
  70.         {
  71.                 return Movement::Block::CantBeFinished;
  72.         }
  73.  
  74.         if (!targetReachable)
  75.         {
  76.                 // Track how much time we spent in this FollowPath block
  77.                 // without being able to reach the movement target.
  78.                 m_accumulatedPathFollowerFailureTime += context.updateTime;
  79.  
  80.                 // If it keeps on failing we don't expect to recover.
  81.                 // We report back that we can't be finished and the planner
  82.                 // will attempt to re-plan for the current situation.
  83.                 if (m_accumulatedPathFollowerFailureTime > 3.0f)
  84.                 {
  85.                         return Movement::Block::CantBeFinished;
  86.                 }
  87.         }
  88.  
  89.         if (m_finishBlockEndDistance > 0.0f)
  90.         {
  91.                 if (pathDistanceToEnd < m_finishBlockEndDistance)
  92.                 {
  93.                         return Movement::Block::Finished;
  94.                 }
  95.         }
  96.  
  97.         IMovementActor& actor = context.actor;
  98.  
  99.         if (result.reachedEnd && !actor.IsLastPointInPathASmartObject())
  100.         {
  101.  
  102.                 const Vec3 velocity = actor.GetAdapter().GetVelocity();
  103.                 const Vec3 groundVelocity(velocity.x, velocity.y, 0.0f);
  104.                 const Vec3 moveDir = actor.GetAdapter().GetMoveDirection();
  105.                 const float speed = groundVelocity.Dot(moveDir);
  106.                 const bool stopped = speed < 0.01f;
  107.  
  108.                 if (stopped)
  109.                 {
  110.                         return Movement::Block::Finished;
  111.                 }
  112.         }
  113.  
  114.         return Movement::Block::Running;
  115. }
  116. }
  117. }
  118.  
downloadMovementBlock_FollowPath.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top