Home > Mobile >  Enemy indicator in 2D space
Enemy indicator in 2D space

Time:07-14

Implemented the enemy indicator, put on the script target and indicator, which is located on the canvas, tied to the camera. The script is built so that the indicator is tied to the position of the edges of the camera, which is not good for the display of this indicator. Can anyone help with the implementation of indenting from the edges of the camera?

Vector3 v_diff = (target.transform.position - _Player.transform.position);             
float atan2 = Mathf.Atan2(v_diff.y, v_diff.x) * Mathf.Rad2Deg;arrow.rotation = 
Quaternion.Euler(0f, 0f, atan2 - 180);              
arrow.position = Vector3.MoveTowards(arrow.position, target.transform.position, 1000);              
Vector3 pos = Camera.main.WorldToViewportPoint(arrow.position);              
pos.x = Mathf.Clamp01(pos.x);             
pos.y = Mathf.Clamp01(pos.y);              
arrow.position = Camera.main.ViewportToWorldPoint(pos);              

CodePudding user response:

If I understood correctly: You want to have a "border" around the area where the indicator can be on the screen.

This can be achieved by using Mathf.Clamp instead of Mathf.Clamp01. For example Mathf.Clamp(pos.x, 0.1f, 0.9f)

P.S. it might help clarifying your question a bit (I can't comment to ask for clarification).

  • Related