【发布时间】:2019-06-08 14:30:00
【问题描述】:
我从一个小型射击游戏开始,但我的角色有问题。手臂必须旋转 360º,但身体只能向右或向左旋转(取决于鼠标旋转手臂的位置)。
到目前为止,我得到的就是您在下面的视频中看到的,但我有两个大问题,并且在教程的帮助下。
我可以旋转和翻转我的手臂,但不能旋转身体。
此外,当它向右射击时,子弹正确地从我创建的火点射出,但在手臂向左翻转后,子弹(和武器射击)不再对齐。
我尝试过的这种方法不是解决这个问题的最佳方法吗?
感谢您的帮助。
游戏链接:https://vimeo.com/310853740
这是我的手臂旋转脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArmRotation : MonoBehaviour
{
SpriteRenderer spriteRend;
void Awake()
{
spriteRend = GetComponent<SpriteRenderer>();
}
void Update()
{
AimArmAtMouse();
}
void AimArmAtMouse()
{
Vector2 mousePosition = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 armToMouse = mousePosition - (Vector2)transform.position;
float rotationZ = Vector2.SignedAngle(transform.right, armToMouse);
transform.Rotate(0f, 0f, rotationZ);
FlipArm(Vector2.SignedAngle(transform.right, Vector2.right));
}
void FlipArm(float rotation)
{
if (rotation < -90f || rotation > 90f)
{
spriteRend.flipY = true;
}
else
{
spriteRend.flipY = false;
}
}
}
【问题讨论】: