I'm trying to see if I can make a character follow the player!
AFAIK, the only game available where this is done is in Intergalactic Wizard Force. So I'm digging through the code to see if I can understand it. ( I reckon this question is mostly for @tulip estuary ๐ )
I'm trying to understand the logic behind this part of the code:
{
// Check camera target pos is within camera
// Camera to position
float toPlayer = character.TargetPosition.x - Camera.GetPosition().x;
float cameraHalfWidth = E.GetCameraGui().orthographicSize * E.GetCameraGui().aspect;
if ( Mathf.Abs(toPlayer) > cameraHalfWidth - 30 )
{
// walk on-screen. Maybe to pre-defined point?
Vector2 targetPos = new Vector2(Camera.GetPosition().x+Mathf.Sign(toPlayer)*(cameraHalfWidth - 60), character.TargetPosition.y+10);
character.WalkToBG( targetPos );
}
} ```
I assume this is the general follow code. Why does it use the camera position? ๐