如果这有所不同,我会使用统一5.1.2。
我有一个游戏对象盾牌,我想围绕一个玩家围成一圈。我有一定程度的工作,盾牌对输入反应良好,但没有动画,因为它只是传送到新位置而不是以平滑的方式绕圈移动。游戏是2D自上而下,所以只能在x / y平面上工作。曾试图使用lerp和slerp但没有获得任何快乐
真的很感谢你帮忙解决这个问题!
这是我到目前为止所拥有的:
public class ShieldMovement : MonoBehaviour {
public Transform target; //player shield is attaced to
float distance = 0.8f; // distance from player so it doesn't clip
Vector3 direction = Vector3.up;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float angle = Mathf.Atan2 (Input.GetAxisRaw("rightH"), Input.GetAxisRaw("rightV"))* Mathf.Rad2Deg;
if(Input.GetAxis("rightH") != 0f || Input.GetAxis("rightV") != 0f)
{
direction = new Vector3(Input.GetAxis("rightH"),Input.GetAxis("rightV"), 0.0f ) ;
}
Ray ray = new Ray(target.position, direction);
transform.position = ray.GetPoint(distance);
if(Input.GetAxis("rightH") != 0f || Input.GetAxis("rightV") != 0f)
{
transform.rotation = Quaternion.AngleAxis(angle,Vector3.forward*-1);
}
}
}
答案 0 :(得分:0)
试试这个。通过对app.post('/somepath', function (req, res, next) {
var hmacReceived = req.headers['x-shopify-hmac-sha256'];
hmac = crypto.createHmac('SHA256',secret);
req.on("data", function(data) {
hmac.update(data);
});
req.on("end", function() {
var calculatedHmac = hmac.digest("base64");
var test1 = hmacReceived === calculatedHmac;
});
req.on("error", function(err) {
return next(err);
});
}
进行如此多的方法调用,您真的只想在开始时调用它一次并将其缓存到变量中以加快速度。另外,你真的不需要检查Input.GetAxis("...")
两次,所以我将所有内容都放入其中一项检查中。我添加了if(Input.GetAxis("rightH") != 0f || Input.GetAxis("rightV") != 0f)
的乘法,希望能为你找到顺利的东西
Time.smoothDeltaTime
答案 1 :(得分:0)
经过大量的搜索和一些帮助,我终于解决了问题,谢谢大家:)这是我提出的解决方案
public class ShieldMovement : MonoBehaviour {
public Transform target; //player shield is attaced to
float distance = 0.8f; // distance from player so it doesn't clip
Vector3 direction = Vector3.up;
public float circSpeed = 0.1f; // Speed Shield moves around ship
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float rh = Input.GetAxisRaw("rightH");
float rv = Input.GetAxisRaw("rightV");
if(Mathf.Abs(rh) > 0.15f || Mathf.Abs(rv) > 0.15f)
{
Vector3 targetDir = new Vector3(rh, rv, 0.0f);
direction = Vector3.Slerp(transform.position-target.position, targetDir, circSpeed);
}
Ray ray = new Ray(target.position, direction); // cast ray in direction of point on circle shield is to go
transform.position = ray.GetPoint(distance); //move shield to the ray as far as the radius
float angleY = transform.position.y - target.position.y;
float angleX = -(transform.position.x - target.position.x);
float angle = Mathf.Atan2 (angleY, angleX) * Mathf.Rad2Deg-90; //Get angle
if(Mathf.Abs(rh) > 0.15f || Mathf.Abs(rv) > 0.15f)
{
transform.rotation = Quaternion.AngleAxis(angle,Vector3.forward*-1); // keep shield facing outwards in respect to player, will need revisiting on animating shield properly
}
}
}