How to apply custom movement system to FollowerEntity?

  • A* version: 5.3.3
  • Unity version: 6000.0.34
  • Recast Graph

Hello. I am trying to convert from RichAI to FollowerEntity.
In RichAI, I set canMove to false and use only the desiredVelocity to move the character using a physics-based system I created. However, I found out that in FollowerEntity, disabling canMove also stops updating desiredVelocity.
All I need is the desiredVelocity, excluding the actual movement. Is it difficult to use this approach with FollowerEntity? Thank you.

Hi

You could remove the tag component SimulateMovementFinalize from the FollowerEntity.entity entity. This will make the agent do all calculations except actually move the agent.

I tried removing it but ‘desiredVelocity’ is not updated from Vector3.zero.

Unity Version : 6000.1.1f1
A* Version : 5.3.7
Grid graph.

Hello,

I have the same concern than Lim. I have disabled the tag, and tested the code with LocalAvoidance2D demo scene.

_follower = GetComponent<FollowerEntity>();

if (_follower == null)
       return;

World world = World.DefaultGameObjectInjectionWorld;
_entityManager = world.EntityManager;

_entity = _follower.entity;

if (_entityManager.HasComponent<SimulateMovementFinalize>(_entity))
      _entityManager.RemoveComponent<SimulateMovementFinalize>(_entity);

It seems to work fine. Then I tried to find a way to get a vector to make my gameobject move manually every frame with the following code :

With desiredVelocity :

direction = _followerEntity.desiredVelocity.normalized
_characterMovement.SetMovement(direction);

With steeringTarget:

 direction = (_followerEntity.steeringTarget - transform.position).normalized;
_characterMovement.SetMovement(direction);

DesiredVelocity doesn’t seem to be relevent. I tryed other solution like using the steeringTarget or managing the movement with the waypoints of the vectorPath array, but no solution give the expected result. I feel bad because the solution should be really simple to get. And I think that this solution will interest a lot of people because it gives the ability to use the FollowerEntity like a computation class, and not necessarly like a movement script which give the ability to integrate in architectures that required to manage the movement with an other class.

Thank you fo your help.

Regards,

To the best of my knowledge, when you want to get the velocity you’ll want to get it from the ResolvedMovement component.

I was able to pull targetPoint like this:

  public void GetDesiredVelocity(){
      var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
      Debug.Log(entityManager.GetComponentData<ResolvedMovement>(follower.entity).targetPoint);
  }

It’s not a “direction” I don’t think but let me know what you think.

Hi,

Thank you for your replay. This solution is suppose to work according to the class documentation. I tested it in the LocalAvoidance2D demo, but it doens’t work. Here is the code I used to realise the test :

using Pathfinding;
using Pathfinding.ECS;
using Unity.Entities;
using UnityEngine;

public class DisableFinalizeMovement : MonoBehaviour
{
    private FollowerEntity _follower;
    private EntityManager _entityManager;
    private Entity _entity;

    void Start()
    {
        _follower = GetComponent<FollowerEntity>();

        if (_follower == null)
            return;

        World world = World.DefaultGameObjectInjectionWorld;
        _entityManager = world.EntityManager;

        _entity = _follower.entity;

        if (_entityManager.HasComponent<SimulateMovementFinalize>(_entity))
        {
            _entityManager.RemoveComponent<SimulateMovementFinalize>(_entity);
        }

    }

    void Update()
    {
        var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        //Debug.Log("Solution 1 : " + _follower.desiredVelocity);
        Debug.Log("Solution 2 : " + entityManager.GetComponentData<ResolvedMovement>(_follower.entity).targetPoint);
    }
}

To test it, I removed 8 robots entities to keep 2 of them. On the first, i added my component.

When I launch the game and I click, the second robot moves to the correct point. The first one doesn’t move, and the console messages doesn’t give the correct information.

The orange gizmos update correctly, so I guess the internal mecanism knows where to go. I can move the character by using the vectorPath , but i won’t benefit from the local avoidance, nor the off mesh links capabilities.

Regards,

Hm, would you be able to start a new thread with your replies copy/pasted in them? This may get a little long and I don’t want the original poster to get tons of notifications spammed from it. Posting a link to this thread in your thread will also post a link to each other so the context won’t be lost :+1: