I would like to use the FollwerEntity component, but without letting it move the character by itself. Instead, i would like to retreive the desired direction each frame to manage the movement with another component.
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 another class.
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()
{
//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.
Thanks for spinning up a new thread on this, it’s appreciated. This may be one I’ll need clarification on from Aron, since ECS is one of my personal weakspots (getting better! sorry for all the tags today @aron_granberg)
Sorry for the “empty” reply, I was looking for this solution but noticed that it hasn’t been any development on the issue for the last 11d, @Bob did you manage to solve it? I’m trying to achieve the same result
Depending on your reason for taking this approach, this is maybe not the solution you want. But - maybe you could let the FollowerAgent script actually move a different, invisible agent, and then infer the direction and velocity from that?
Unfortunately, I didn’t had the time to dig more this issue. I know some basics of ECS, but probably not enough to do something clean to retrieve what we want. I thing discussing with @aron_granberg about this subject can be more effective.
I use the Top Down Engine asset. Architecturally, we are supposed to move our characters using the CharacterMovement script because it has for example impacts on animations, and we can also have some situations where the character is not supposed to be able to move. So it is better to let each component be responsible for its job (a CharacterMovement that moves the character with the responsibility of playing movement feedbacks, specifying the speed and so on, a Brain that decides what to do, and a Pathfinder that compute a path and tells how to go to a certain point on the map).
Your workaround should work on the paper, but I would prefer a cleaner approach if possible (more performant and easier code to read and understand). Thanks for your idea.
Thank you very much for your reply and the fix. I will test the solution on the next update when it will be available and give you the resultats of my tests.