Перекрестие, следующее за положением мыши вдоль оси Y игрока в 2d игре сверху вниз? - PullRequest
0 голосов
/ 01 октября 2019

Я программирую 2d нисходящую игру с Unity о космических кораблях. На самом деле звездолет находится в центре экрана ( 0x.0y ). Звездолеты вращаются вдоль его оси с задержкой, пока она не достигнет положения мыши с его осью y.
Я хочу сделать перекрестие, которое остается на оси y корабля и следит за его вращением, чтобы показать, куда именно указывает корабль. делать отложенное вращение. Перекрестие должно всегда достигать центра курсора мыши, когда корабль выровнен с мышью. Это перекрестие является переменной Transform, называемой «цель».
Любая помощь будет принята. Вот что я попробовал: '' 'C #

public Transform aim;//AIM position "aim image"
public float aimSpeed;//speed AIM
public float zonaMorta;//death zone value where the AIM can't move

private Vector3 target;//position where the AIM need to go
private Vector3 posAim;//AIM position

void Update ()
    {
        float pr = transform.rotation.z;//take the rotation value from the player
        float ty = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;//y axis value of the mouse.
        target = new Vector3(0 , ty, 0);//allowance the y axis of the cursor to "target"
        posAim = aim.transform.position;//allowance AIM position to "posAim"
        posAim = new Vector3(0, posAim.y, 0);//on posAim I keep only y while x, z gate them

        if(posAim.y + zonaMorta > target.y && posAim.y - zonaMorta < target.y)//if AIM is between this two value then it can't move, it can't move in the y axis
    {

    }else{

        if(pr > -90f || pr < 90f){//if the rotation of the player is more than -90 degrees or less than 90 degrees then ..
            if(posAim.y > target.y)//if y axis of AIM is greater than the y axis of the cursor then..
            {
                aim.transform.position -= aim.transform.up * aimSpeed;//subtract and allowance at the AIM position a positive velocity in the y axis
            }
            if(posAim.y < target.y)//if y axis of AIM is lesser than the y axis of the cursor then..
            {
                    aim.transform.position += aim.transform.up * aimSpeed;//sum and allowance at the AIM position a positive velocity in the y axis
                }                   
                }
      if(pr < -90f || pr > 90f){//if the rotation of the player is less than -90 degrees or more than 90 degrees then ..

            if(posAim.y > target.y)//if y axis of AIM is greater than the y axis of the cursor then..
            {
                aim.transform.position -= -aim.transform.up * aimSpeed;//subtract and allowance at the AIM position a negative velocity in the y axis
            }
            if(posAim.y < target.y)//if y axis of AIM is lesser than the y axis of the cursor then..
            {
                    aim.transform.position += -aim.transform.up * aimSpeed;//sum and allowance at the AIM position a negative velocity in the y axis
                }                   
                }
            }
        }

' ''

В этом случае я создал мертвую зону, но этот метод не работает Как исключение: перекрестие, когдакорабль движется, всегда будет идти вверх и вниз вдоль оси y. Я читал о Vector3.Lerp, но на самом деле я не знаю, как его использовать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...