unity如何选择rigidboy和character controller

这篇博客探讨了在Unity中使用Character Controller和Rigidbody组件的差异,特别是在移动、碰撞处理和跳跃行为上的不同。Character Controller适合不需要精确物理交互但能轻松处理楼梯等复杂场景的情况,而Rigidbody则适用于需要严格物理模拟且可以简化代码的场合。两者都可以实现所需功能,但选择取决于具体项目需求。
摘要由CSDN通过智能技术生成

通过下面场景来确定两个常见方法在移动,条约,碰撞上的区别。

character controller的优点:

  1. 不会产生过分的物理交互,同样的需要的物理交互要自己编写。
  2. 虽然有isgrounded这个方法,但是可能有bug,可以用Physics.CheckSphere((Vector3 position, float radius,LayerMask)来判断物体是否于地面接触。
  3. 跳跃:_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
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值