2015-01-22 5 views
0

화면 영역을 클릭하고 우주선이 향하고있는 방향으로 가속하면서 해당 방향으로 회전하게하십시오 ... 회전 작동이 있지만 보이지 않습니다. 이것은 일반적으로 작동회전 방향으로 이동

Vector3 currentPosition = transform.position; 

    if (Input.GetButton("Fire1")) { 
     Vector3 moveToward = Camera.main.ScreenToWorldPoint(Input.mousePosition); 
     moveDirection = moveToward - currentPosition; 
     moveDirection.z = 0; 
     moveDirection.Normalize(); 
    }  

    float targetAngle = Mathf.moveDirection(vector.y, moveDirection.x); 

    transform.rotation = Quaternion.Slerp(transform.rotation, 
         Quaternion.Euler(0, 0, targetAngle), 
              rotateSpeed * Time.deltaTime); 

    Vector2 direction; 
    direction.x = Mathf.Cos((targetAngle * Mathf.Deg2Rad)); 
    direction.y = Mathf.Sin((targetAngle * Mathf.Deg2Rad)); 
    direction.Normalize(); 

    velocity.x = direction.x * moveSpeed; 
    velocity.y = direction.y * moveSpeed;   
    rigidbody2D.velocity = velocity;   

답변

1

:

내 코드는 내가 가고 싶어 결국하지가 현재 직면하고 어디 어디를 향해 배를 보냅니다 선박이 직면하고있는 방향으로 힘을 적용하는 방법을 알아낼 회전을 할 수있는 이런 종류의 상황에서 :

Vector2 direction = transform.forward; 
rigidbody2D.velocity = direction * moveSpeed; 

장면 레이아웃을 알지 못하면 확실하게 알 수 없습니다.

반대 방향으로 선박을 이동하는 경우 - transform.forward을 사용하거나 배가 옆으로 이동하는 경우 transform.right을 사용하십시오.

관련 문제