BVB Source Codes

CRYENGINE Show MovementHelpers.cpp Source code

Return Download CRYENGINE: download MovementHelpers.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 <CryAISystem/MovementUpdateContext.h>
  5. #include "MovementActor.h"
  6. #include "PipeUser.h"
  7. #include "MovementHelpers.h"
  8.  
  9. namespace Movement
  10. {
  11. namespace Helpers
  12. {
  13.  
  14. // ----------------------------------------------------------------
  15. // Stuck Detector
  16. // ----------------------------------------------------------------
  17.  
  18. StuckDetector::StuckDetector()
  19.         : m_accumulatedTimeAgentIsStuck(0.0f)
  20.         , m_agentDistanceToTheEndInPreviousUpdate(std::numeric_limits<float>::max())
  21. {
  22. }
  23.  
  24. void StuckDetector::Update(const MovementUpdateContext& context)
  25. {
  26.         const EntityId actorEntityId = context.actor.GetEntityId();
  27.         IEntity* pEntity = gEnv->pEntitySystem->GetEntity(actorEntityId);
  28.         const Vec3& pipeUserPosition = pEntity->GetPos();
  29.  
  30.         const float distToEnd = context.pathFollower.GetDistToEnd(&pipeUserPosition);
  31.         const float treshold = 0.05f;
  32.         if (distToEnd + treshold < m_agentDistanceToTheEndInPreviousUpdate)
  33.         {
  34.                 m_agentDistanceToTheEndInPreviousUpdate = distToEnd;
  35.                 m_accumulatedTimeAgentIsStuck = 0.0f;
  36.         }
  37.         else
  38.         {
  39.                 m_accumulatedTimeAgentIsStuck += context.updateTime;
  40.         }
  41. }
  42.  
  43. bool StuckDetector::IsAgentStuck() const
  44. {
  45.         const float maxAllowedTimeAgentCanBeStuck = 3.0f;
  46.         return m_accumulatedTimeAgentIsStuck > maxAllowedTimeAgentCanBeStuck;
  47. }
  48.  
  49. void StuckDetector::Reset()
  50. {
  51.         m_accumulatedTimeAgentIsStuck = 0.0f;
  52.         m_agentDistanceToTheEndInPreviousUpdate = std::numeric_limits<float>::max();
  53. }
  54.  
  55. void BeginPathFollowing(IMovementActor& actor, const MovementStyle& style, const CNavPath& navPath)
  56. {
  57.         actor.GetAdapter().SetActorPath(style, navPath);
  58.         actor.GetAdapter().SetActorStyle(style, navPath);
  59. }
  60.  
  61. // Returns false when target is unreachable
  62. bool UpdatePathFollowing(PathFollowResult& result, const MovementUpdateContext& context, const MovementStyle& style)
  63. {
  64.         context.actor.GetAdapter().ConfigurePathfollower(style);
  65.  
  66.         IPathFollower& pathFollower = context.pathFollower;
  67.         const Vec3 position = context.actor.GetAdapter().GetPhysicsPosition();
  68.         const Vec3 velocity = context.actor.GetAdapter().GetVelocity();
  69.  
  70.         const bool targetReachable = pathFollower.Update(result, position, velocity, context.updateTime);
  71.  
  72.         if (targetReachable)
  73.         {
  74.                 context.actor.GetAdapter().SetMovementOutputValue(result);
  75.         }
  76.         else
  77.         {
  78.                 context.actor.GetAdapter().ClearMovementState();
  79.         }
  80.  
  81.         return targetReachable;
  82. }
  83. }
  84. }
  85.  
downloadMovementHelpers.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