Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 统一角色跳跃时不移动_C#_Unity3d_Game Engine_Game Physics - Fatal编程技术网

C# 统一角色跳跃时不移动

C# 统一角色跳跃时不移动,c#,unity3d,game-engine,game-physics,C#,Unity3d,Game Engine,Game Physics,大家好,谢谢大家阅读我的问题,我正在使用unity 5创建永久跑步者游戏,我希望我的角色跳过障碍物,但我希望对象在跳跃过程中向前移动,但我的跳跃时间很短,角色离地面很近,即使我在代码中对它施加了一个力,也不能向前移动,所以我能做什么呢 void Start () { anim = GetComponent<Animator>(); rbody = GetComponent<Rigidbody>(); verticalJumpPower = 80f

大家好,谢谢大家阅读我的问题,我正在使用unity 5创建永久跑步者游戏,我希望我的角色跳过障碍物,但我希望对象在跳跃过程中向前移动,但我的跳跃时间很短,角色离地面很近,即使我在代码中对它施加了一个力,也不能向前移动,所以我能做什么呢

void Start () 
{
    anim = GetComponent<Animator>();
    rbody = GetComponent<Rigidbody>();
    verticalJumpPower = 80f;
    horizantalJumpPower = 1000f;
    playerVelocity = 10f;
    isGrounded = true;
}

***in update function :*** 

if(Input.GetKeyDown (KeyCode.UpArrow))
{
    rbody.AddForce(new Vector3(0,verticalJumpPower,horizantalJumpPower));
    anim.SetBool("jump",true);
    isGrounded = false;


    } 
void Start()
{
anim=GetComponent();
rbody=GetComponent();
垂直跳线功率=80f;
水平跳跃功率=1000f;
playerVelocity=10f;
isGrounded=true;
}
***在更新功能中:**
if(Input.GetKeyDown(KeyCode.UpArrow))
{
rbody.AddForce(新矢量3(0,垂直跳线功率,水平跳线功率));
动画挫折(“跳跃”,真实);
isfounded=false;
} 

我添加了
anim.applyRootMotion=false
成功了

尝试将
ForceMode
类型更改为
ForceMode.pulse
。i、 e.
rBody.AddForce(新矢量3(0,垂直跳线功率,水平跳线功率),ForceMode.pulse)它对施力有效,但角色仍然无法在空中向前移动。这是2D游戏吗?检查已对齐游戏世界的轴。您可能需要将Vector3构造函数更改为
horizontalJumpPower,verticalJumpPower,0
。我确信我是在z方向上运行的。我添加了anim.applyRootMotion=false;它成功了