我想沿着另一個gameobject的輪廓移動一個gameObject的實例。它是一個統一的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左側的位置旋轉有時也被關閉。我試圖用Quaternion.LookRotation(hit.normal)使用Instantiate(),但也沒有運氣。
任何幫助表示讚賞。謝謝!