我对Unity(以及一般的游戏开发)都很陌生。我遵循了很棒的简单教程Survival Shooter,我有一个问题:在本教程中,我们将一个Y约束位置添加到刚体的角色加上我们将拖动值和角度拖动值设置为无限。我们怎样才能使角色跳跃,因为这些设置会阻止角色移动到Y轴?
如果有人能帮我一把,请...
非常感谢!
答案 0 :(得分:0)
为什么要在Y轴上添加约束?您可以将其移除,然后只需添加重力即可让您的玩家坚持到地面。在那之后,只需施加一个力,或者只是一个简单的平移,以设定的速度向上移动,让玩家跳跃,然后等待引力让他退缩。
答案 1 :(得分:0)
这就是我要做的事情 附:你需要在矢量
上删除Y轴上的约束using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
public Vector3 force;
public Rigidbody rb;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.Space) && transform.position.y == 0) //Enter your y axix where ground is located or try to learn a little more about raycasting ill just use 0 for an example)
{
rb.AddForce(force);//Makes you jump up when you hold the space button down line line 19 will do so that you only can jump when you are on the ground.
} if (Input.GetKeyUp(KeyCode.Space))
{
rb.AddForce(-force); //When you realase the force gets inverted and you come back to ground
}
}
}
答案 2 :(得分:-1)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Just : MonoBehaviour {
public Vector3 force;
public Rigidbody rb;
bool isGrounded;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true) //Rember to got to your "Ground" object and tag it as Ground else this would not work
{
rb.AddForce(force);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Ground")
{
isGrounded = true;
}
}
void OnCollisionExit(Collision collision)
{
isGrounded = false;
}
}
您需要为地面对象指定一个名为Ground的标记,您需要制作一个名为Ground的标记,而不是您点击对象并且检查员的左上角有标记然后你就是这么难制作一个名为Ground的新标签。并且plz rember为你的玩家对象分配其他值。