I’m using the Tile Based Map Nav asset for a board game. It doesn’t have a sample with melee units so I have to make it without reference. I’m trying to make the unit walk up to it’s target without going to it’s target center. I assigned the units a radius float, so the unit stops without going inside the other one. The problem I’m having is getting the angle between both units in a Vector3 regardless of the direction the target is facing. This is my code so far:
Vector3 attackDirection = transform.position - target.transform.position;
float attackSide = Vector3.Dot(Vector3.right,attackDirection);
float targetAngle = Vector3.Angle(Vector3.forward,attackDirection);
Quaternion rot = Quaternion.AngleAxis(targetAngle*attackSide,Vector3.up);
Vector3 attackPos = rot * Vector3.forward;
iTween.MoveTo(gameObject, iTween.Hash("position",attackPos,
"speed", ((moveSpeedMulti * followMaxMoves) + 1f) * moveSpeed,
"orienttopath", true,
"easetype", "linear"));
The attacker seems to stop at the correct distance, but he is a few angles off, and sometimes in the completely wrong angle. What exactly am I doing wrong in my code?