다른 게임 개체의 윤곽을 따라 gameObject의 인스턴스를 이동하려고합니다. Unity에서의 2D 프로젝트.Raycast2D에서 개체 인스턴스화 및 인스턴스 회전
내 현재 코드 :
Vector3 mousePosition = m_camera.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(new Vector2(mousePosition.x, mousePosition.y), new Vector2(player.transform.position.x, player.transform.position.y));
if (hit.collider != null && hit.collider.gameObject.tag == "Player") {
if (!pointerInstance) {
pointerInstance = Instantiate(ghostPointer, new Vector3(hit.point.x, hit.point.y, -1.1f), Quaternion.identity);
} else if(pointerInstance) {
pointerInstance.gameObject.transform.position = new Vector3(hit.point.x, hit.point.y, -1.1f);
pointerInstance.gameObject.transform.eulerAngles = new Vector3(0f, 0f, hit.normal.x);
}
}
는 불행하게도, 게임 오브젝트가 마우스와 playerObject의 왼쪽에있는 위치를 향해 회전하지 않는 때로는 오프에 있습니다. Instantiate()를 Quaternion.LookRotation (hit.normal)과 함께 사용하려했지만 행운이 없었습니다. 여기
내가 무엇을 달성하고자하는의 거친 스케치
는 :![instance of tree is shown on the surface of the player facing towards the mousepointer](https://i.stack.imgur.com/KSSiS.png)
어떤 도움에 감사드립니다. 감사!