Add setter for crword agent position and velocity

This commit is contained in:
Wojtek Figat
2024-03-30 22:29:43 +01:00
parent 294b4c4006
commit c5e1abb08c
2 changed files with 32 additions and 0 deletions

View File

@@ -104,6 +104,15 @@ Vector3 NavCrowd::GetAgentPosition(int32 id) const
return result;
}
void NavCrowd::SetAgentPosition(int32 id, const Vector3& position)
{
dtCrowdAgent* agent = _crowd->getEditableAgent(id);
if (agent)
{
*(Float3*)agent->npos = Float3(position);
}
}
Vector3 NavCrowd::GetAgentVelocity(int32 id) const
{
Vector3 result = Vector3::Zero;
@@ -115,6 +124,15 @@ Vector3 NavCrowd::GetAgentVelocity(int32 id) const
return result;
}
void NavCrowd::SetAgentVelocity(int32 id, const Vector3& velocity)
{
dtCrowdAgent* agent = _crowd->getEditableAgent(id);
if (agent)
{
*(Float3*)agent->nvel = Float3(velocity);
}
}
void NavCrowd::SetAgentProperties(int32 id, const NavAgentProperties& properties)
{
dtCrowdAgentParams agentParams;

View File

@@ -63,6 +63,13 @@ public:
/// <returns>The agent current position.</returns>
API_FUNCTION() Vector3 GetAgentPosition(int32 id) const;
/// <summary>
/// Sets the agent current position.
/// </summary>
/// <param name="id">The agent ID.</param>
/// <param name="position">The agent position.</param>
API_FUNCTION() void SetAgentPosition(int32 id, const Vector3& position);
/// <summary>
/// Gets the agent current velocity (direction * speed).
/// </summary>
@@ -70,6 +77,13 @@ public:
/// <returns>The agent current velocity (direction * speed).</returns>
API_FUNCTION() Vector3 GetAgentVelocity(int32 id) const;
/// <summary>
/// Sets the agent current velocity (direction * speed).
/// </summary>
/// <param name="id">The agent ID.</param>
/// <param name="position">The agent velocity (direction * speed).</param>
API_FUNCTION() void SetAgentVelocity(int32 id, const Vector3& velocity);
/// <summary>
/// Updates the agent properties.
/// </summary>