【发布时间】:2018-08-03 12:07:54
【问题描述】:
我正在 DS 上使用勇者斗恶龙英雄火箭史莱姆重建一个运动系统。在该游戏中,玩家可以按住 A 按钮并将史莱姆主角向一个方向伸展。在 A 被拉长的时候放开它会使它们朝那个方向甩掉。
这是它的 gif 图像:
注意他是如何从对角线上反弹的。我的复制目前看起来像这样(忽略错误动画:P)
看起来不错!但是,如果我要斜着撞墙,我只会朝相反的方向向后移动,而不是反射它。
这是我如何处理墙壁反弹的代码。
IEnumerator wallBounce(Vector2 hitVelocity)
{
playerAnimator.enabled = true;
yield return new WaitForSeconds(.3f);
playerAnimator.CrossFade("Walking " + curDirection, 0); // place holder animation
pVelocity = Vector2.Scale(-pVelocity,new Vector2(0.25f,0.25f));
endPos = transform.position + new Vector3(pVelocity.x, pVelocity.y);
transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
curState = state.blasting;
transform.position = Vector3.MoveTowards(transform.position, endPos, 5f * Time.deltaTime);
}
我知道 Unity 中的 Vector3.Reflect 方法,但我不确定如何在我当前的代码中实现它。
【问题讨论】: