我制作了一个枪械系统,我需要拿起我产生的枪支,但是问题是,当我拿起枪支时,由于玩家的旋转,它不会在我想要的位置产生。这是一张图片:https:// netane54544-gmail.tinytake.com/media/75f9e3?filename=1525456534383_04-05-2018-08-53-27.png&sub_type=thumbnail_preview&type=attachment&width=1198&height=654另外这是枪的另一张照片,只是为了展示我要去的东西:https : //netane54544-gmail.tinytake.com/media/75f9f5?filename=1525456736315_04-05-2018-08-56-51.png&sub_type = thumbnail_preview&type = attachment&width = 1198&height = 654这是我正在使用的代码:foreach (Gun item in gunList) { if (item.gunType == "Normal" && guns_inInventory[playerScript.keyPress] == false) { playerGuns[playerScript.keyPress] = Instantiate(Weapon_Normal, Camera.main.transform.position + Normalview.offSetPosition, Quaternion.identity) as GameObject; playerGuns[playerScript.keyPress].name = gunName; playerGuns[playerScript.keyPress].transform.parent = gameObject.transform; playerGuns[playerScript.keyPress].transform.eulerAngles = Normalview.startOffsetRotation; setGunActive(playerScript.keyPress); //Store gundata in inventory item.Named = false; Inventory[playerScript.keyPress] = item; guns_inInventory[playerScript.keyPress] = true; } else if (item.gunType == "Stride" && guns_inInventory[playerScript.keyPress] == false) { playerGuns[playerScript.keyPress] = Instantiate(Weapon_Stride, Camera.main.transform.position + Normalview.offSetPosition, Quaternion.identity) as GameObject; playerGuns[playerScript.keyPress].name = gunName; playerGuns[playerScript.keyPress].transform.parent = gameObject.transform; playerGuns[playerScript.keyPress].transform.eulerAngles = Strideview.startOffsetRotation; } }我试图找到问题,但被卡住了。
1 回答
繁星coding
TA贡献1797条经验 获得超4个赞
NormalView.offSetPosition 仅在不旋转时存储位移。
例如,假设您offsetPosition是Vector(0,0,1):
Camera.main.transform.position + NormalView.offSetPosition 将采用相机的位置,并始终添加矢量(0,0,1),该矢量在世界轴上实际上向前1个单位,从而有效地忽略了相机的旋转。
要解决此问题,请将您的实例化位置更改为:
Camera.main.transform.position +
(Camera.main.transform.forward * NormalView.offSetPosition.z) +
(Camera.main.transform.right * NormalView.offSetPosition.x) +
(Camera.main.transform.up * NormalView.offSetPosition.y)
通过获取受其旋转影响的相机的前向/右/上矢量,这考虑了相机的旋转。通过将其乘以偏移量(在该方向上的距离),它将始终在相对于角色的相同位置处生成,而与相机的旋转无关。
- 1 回答
- 0 关注
- 124 浏览
添加回答
举报
0/150
提交
取消