如何在unity 3d中跳跃和前进?

how to make jump and step forward in unity 3d?

玩家必须按下按钮,角色才能向前移动一步,但是是跳跃式的。

using System.Collections.Generic;
using UnityEngine;

public class playerrr : MonoBehaviour
{
    public void MoveUp()
    {
        transform.Translate(0f, 0f, 1f);
    }
    public void MoveLeft()
    {
        transform.Translate(-1f, 0f, 0f);
    }
    public void MoveRight()
    {
        transform.Translate(1f, 0f, 0f);
    }
}

而且向左和向右的移动必须不是90度,而是大约40度。

1.-“但是一跃而起”。
你可以查看Transform.Translate documentation。 转换发生在执行指令的“突然”时刻,这意味着“立即”应用运动。如果您希望它是渐进的,文档本身中有一个示例可以做到这一点:

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        // Move the object forward along its z axis 1 unit/second.
        transform.Translate(Vector3.forward * Time.deltaTime);

        // Move the object upward in world space 1 unit/second.
        transform.Translate(Vector3.up * Time.deltaTime, Space.World);
    }
}

2.-“不是 90 度,而是大约 40 度。”
然后你需要计算那个方向并移动到那里。请注意,您可以在参数中选择“Space.Self”来定义平移,同时考虑到感兴趣的游戏对象的局部轴系统(通常与 this 对齐),然后您选择一个点符合您的翻译要求。
我会尝试:
向右 45º:Vector3(1, 0, 1)
向左 45º:Vector3(-1, 0, 1)
向右 40º:Vector3(Mathf.sin(Mathf.Deg2Rad(40)), 0, Mathf.cos(Mathf.Deg2Rad(40)))
向左 40º:Vector3(-Mathf.sin(Mathf.Deg2Rad(40)), 0, Mathf.cos(Mathf.Deg2Rad(40)))

对于所需方向的距离 d,将其包括在您的点计算中: 向右 d 40º 的距离:
d * Vector3(Mathf.sin(Mathf.Deg2Rad(40)), 0, Mathf.cos(Mathf.Deg2Rad(40)))
向左 d 40º 的距离:
d * Vector3(-d * Mathf.sin(Mathf.Deg2Rad(40)), 0, Mathf.cos(Mathf.Deg2Rad(40)))