【发布时间】:2017-12-12 16:27:58
【问题描述】:
好的,我试图让我的对象(玩家)跳跃一切都可以,直到我撞到墙并继续撞墙(仍然 W 向下)如果我停止行走,我不能跳我撞到墙上,他将被启用为了跳跃,我尝试让墙壁触碰以使玩家的速度 = 零,但它不起作用, 我试图在墙壁上添加刚体并将它们冻结在适当的位置,试图使它们运动学也不起作用。
我希望我能靠在墙上并继续靠着它们走,以便能够跳跃。 如果你知道我该怎么做,请分享谢谢。
这是移动脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveScript : MonoBehaviour {
private float speed;
private float jumpHight;
private float straffeSpeed;
private float fallMultiplier;
private Rigidbody rig;
private Collider coll;
// Use this for initialization
private void Awake()
{
rig = GetComponent<Rigidbody>();
coll = GetComponent<Collider>();
straffeSpeed = 1.5f;
fallMultiplier = 2.5f;
speed = 10f;
jumpHight = 4f;
}
void Start () {
GroundCheck();
}
// Update is called once per frame
void Update () {
Move();
GroundCheck();
BetterFall();
}
private void Move()
{
float hAxis = Input.GetAxis("Horizontal") * straffeSpeed;
float vAxis = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(hAxis, 0, vAxis) * speed * Time.deltaTime;
rig.MovePosition(transform.position + movement);
if (Input.GetKey(KeyCode.Space) && GroundCheck())
{
rig.velocity = Vector3.up * jumpHight;
}
}
private bool GroundCheck()
{
return Physics.Raycast(transform.position, -Vector3.up, coll.bounds.extents.y + 0.2f);
}
private void BetterFall()
{
if(rig.velocity.y < 0)
{
rig.velocity += Vector3.up * Physics.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
}
}
【问题讨论】:
-
根据墙体材料/物理特性,您可能会遇到摩擦。如果你靠在墙上并试图从墙上跳下来,摩擦力可能会阻止你。根据您制作的游戏类型,您的关卡对象不应引起摩擦。