问题描述
我正在尝试制作一个类似《黑暗之魂》的游戏,其中有一个可以滚动和冲刺的角色。在使用射线投射实现跌倒机制后(如果没有地面检测到跌倒;如果已经跌落,则播放动画)Here
这是为了阻止玩家能够在空中四处走动...说他走出了边缘,重力逐渐将他向下漂移。
虽然他正在下沉并且仍然能够四处移动,但是他可以向后滚动并向后退一步(他应该跌倒了)。尽管当他降落在任何物体上时,他将无法滚动或后退。只是四处走动并冲刺(运动混合树)与下一段相同的问题
在将isInAir变量= true移到if语句外,但仍*在else块内,以确保玩家是否摔倒时。那么下降动画将起作用。 动画效果下降,太棒了!但是现在我在无法完成动画的对象上。 Here
顺便说一句-crossFade设置为零(在animationHandler.PlayTargetAnimation函数内部)以达到这个目标,否则我的动画帧将冻结在运动混合树上,同时仍然能够四处移动而不滚动(不甚至覆盖一个人的距离)
控制台记录目标动画以及玩家是否摔倒。两者都是准确的...
TLDR-当播放器位于任何对象之上时,播放器无法完成动画
动画 ANIMATIONS
脚本 SCRIPTS
这实际上是来自视频教程系列的代码,该代码是逐字记录的,但无法正常工作...除了一些日志和对isInAir的位置分配的更改之外,它的代码相同。 参考:https://www.youtube.com/playlist?list=PLD_vBJjpCwJtrHIW1SS5_BNRk6KZJZ7_d
我完全评论了此功能,现在我以缓慢的速度下降,但没有动画,但我至少可以在表面滚动!
public void HandleFalling(float delta,Vector3 moveDirection)
{
playerManager.isGrounded = false;
RaycastHit hit;
Vector3 origin = myTransform.position;
origin.y += groundDetectionRayStartPoint;
//IF SOMETHING IS DIRECTLY IN FRONT OF YOU,YOURE NOT MOVING
if (Physics.Raycast(origin,myTransform.forward,out hit,0.6f))
{
moveDirection = Vector3.zero;
}
if(playerManager.isInAir)
{
rigidbody.AddForce(-Vector3.up * fallSpeed);
rigidbody.AddForce(moveDirection * fallSpeed / 10f );
}
Vector3 dir = moveDirection;
dir.Normalize();
origin = origin + dir * groundDirectionRayDistance;
targetPosition = myTransform.position;
//DEBUGGER
Debug.DrawRay(origin,-Vector3.up * minimumDistanceToBeginFall,Color.red,0.1f,false);
//grounded
if (Physics.Raycast(origin,-Vector3.up,minimumDistanceToBeginFall,ignoreForGroundCheck))
{
normalVector = hit.normal;
Vector3 tp = hit.point;
playerManager.isGrounded = true;
targetPosition.y = tp.y;
if (inAirTimer > 0.5f)
{
Debug.Log("you were in the air for " + inAirTimer);
animatorHandler.PlayTargetAnimation("Unarmed-Land",false);
inAirTimer = 0;
}
else
{
animatorHandler.PlayTargetAnimation("Locomotion",false);
inAirTimer = 0;
}
playerManager.isInAir = false;
}
else //falling
{
Debug.Log("falling");
playerManager.isInAir = true; //added to fix fall animation bug *******************
if (playerManager.isGrounded)
{
playerManager.isGrounded = false;
}
if (playerManager.isInAir == true)
{
if (playerManager.isInteracting == false)
{
animatorHandler.PlayTargetAnimation("Falling",true);
}
Vector3 vel = rigidbody.velocity;
vel.Normalize();
rigidbody.velocity = vel * (movementSpeed/2);
// if commented from the top and uncommented here,then rolls work but fall doesnt *******************
// playerManager.isInAir = true;
//When player is touching ground no matter what is commented out from above,PLAYER CANNOT ROLL WHILE TOUCHING GROUND
}
}
if (playerManager.isGrounded)
{
if (playerManager.isInteracting || inputHandler.moveAmount > 0 )
{
myTransform.position = Vector3.Lerp(myTransform.position,targetPosition,Time.deltaTime);
}
else
{
myTransform.position = targetPosition;
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)