【发布时间】:2021-02-05 00:13:12
【问题描述】:
当我跳到一个立方体物体上时,我达到了步距偏移,它在再次落到地上之前会抖动一点。我可以完全消除步距偏移,但这不是我想要的,因为我的游戏是围绕跑酷进行的。当我做这个时,我正在关注 YouTube 上的 Brackeys 教程。 Brackeys tutorial. 谁能帮帮我? ,first person object , the object causing most problems, objects in scene
using System.collections;
using System.Collections.Generic;
using UnityEngine;
public class keymovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -10f;
public Transform groundcheck;
public float groundDistance = 0.5f;
public LayerMask groundMask;
public float jumpheight = 3f;
Vector3 velocity;
bool isgrounded;
void Update()
{
isgrounded = Physics.CheckSphere(groundcheck.position, groundDistance, groundMask);
if (isgrounded && velocity.y < 0)
{
velocity.y = -2;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
if (Input.GetButton("jump") && isgrounded)
{
velocity.y = Mathf.Sqrt(jumpheight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
}
}
【问题讨论】:
-
我没有添加刚体