通过下面场景来确定两个常见方法在移动,条约,碰撞上的区别。
character controller的优点:
- 不会产生过分的物理交互,同样的需要的物理交互要自己编写。
- 虽然有isgrounded这个方法,但是可能有bug,可以用Physics.CheckSphere((Vector3 position, float radius,LayerMask)来判断物体是否于地面接触。
- 跳跃:_velocity.y += JumpForce;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character : MonoBehaviour
{
public float Speed = 5f;
public float JumpHeight = 2f;
public float Gravity = -9.81f;
public float GroundDistance = 0.2f;
public float DashDistance = 5f;
public LayerMask Ground;
public Vector3 Drag;
private CharacterController _controller;
priva