- A* version: 5.2.4
- Unity version: 6000.0.24
I’m using FollowerEntity to create an enemy AI. It’s a 3D souls-like game and I wanted to implement a simple function that makes the enemy Strafe when he’s close to the player.
I have two transforms as targets. One is Position Target and one is Look At Target. I assigned Position Target to the target variable of AIDestinationSetter and Look At Target to a separate script that I created. What I did was very simple. I set FollowerEntity.rotation to the direction in which the AI is looking at the Look At Target.
I simply predicted that the AI would move to the Position Target and rotate to look at the Look At Target.
However, the AI could only move in the direction it was looking, and it couldn’t move if the rotation direction was too different from the direction in which the Position Target was.
I don’t know if this is the intended behavior, but I’m curious how to change the position and rotation when using FollowerEntity.
P.S. I tried to attach a 2.5MB GIF file, but it was canceled because it said that files over 16MB are restricted. The sizing seems weird, but I’ve added a Google Drive link to the GIF below anyway.
GIF
Hmm this might be a case where it would help if you could post your code as well, if you can I also recommend checking out this page of the documentation about an example script for circling a target.
Here is the code. I originally used AIDestinationSetter to specify the location, but I simplified it into code. The result is the same.
void Update()
{
followerEntity.destination = destinationTarget.position;
followerEntity.rotation = Quaternion.LookRotation(lookAtTarget.position - transform.position);
}
In this code, I expected:
-
AI moves to the location of destinationTarget.position.
-
AI looks in the direction of lookAtTarget.
2 worked, but 1 didn’t.
I read the manual for MoveInCircle and actually tested it, but this only makes the AI rotate around the target, and the AI still only looks in the direction it is moving. In other words, rotation and velocity can’t be handled separately.
What I want is for the AI to move left and right while looking at the player. I think this was possible when I used RichAI a long time ago, so I think it’s a bug.
I solved this problem now.
After separating the Rotation Sync of FolliwerEntity, I used FollowerEntity.transform.rotation instead of FollowerEntity.rotation.
Eyup that’s exactly where I was gonna go after reading your previous reply, nicely done!