I have in my scene an enemy that comes close to the player. Use Vector3.Distance. I wanted to optimize movement with heuristics. How can I do?
Vector3 dist = spawn.transform.position - this.transform.position;
Vector3 distNorm = dist.normalized;
this.transform.transform.position += distNorm * speed * Time.deltaTime;
float heuristic (Vector3 pos)
{
float X = Mathf.Abs(pos.x - this.transform.position.x);
float Y = Mathf.Abs(pos.y - this.transform.position.y);
return X + Y;
}
Your code you shown doesn’t use Vector3.Distance anywhere…
Also, VectorA - VectorB is not the ‘distance’ between two vectors. It is a vector that points from VectorB to VectorA. You can get the distance between them by calculating the magnitude (length) of the vector, but that does not make it the ‘dist’.
@lordofduct replace the variable name “dist” with “dir” and it works
what I’m really struggling with is that the first chunk of code goes directly towards the target, which is going to be “shortest” path unless there are obstacles in the way… in which case we’re talking pathfinding…
or do you mean the target is moving and you want to move towards an intercept point, in which case we’re talking steering behaviours…
unfortunately “heuristics” isn’t enough detail on it’s own, it’s a general term for “some ‘clever stuff’ that means we get to a ‘suitably good’ result ‘quicker’”. Without knowing the details of what you are trying to achieve its hard to define “clever stuff”, “suitably good” or “quicker” in that