没有合适的资源?快使用搜索试试~ 我知道了~
charactor controller角色平衡木问题解决办法2
需积分: 0 0 下载量 105 浏览量
2022-08-08
19:57:50
上传
评论
收藏 45KB DOCX 举报
温馨提示
试读
2页
charactor controller角色平衡木问题解决办法 Posted on 2013年06月13日 by U3d / Unity3D脚本/插件/被围观
资源详情
资源评论
资源推荐
charactor controller 角色平衡木问题解决办法
Posted on 2013 年 06 月 13 日 by U3d / Unity3D 脚本/插件/被围观 37 次
charactor controller 角色做平衡木的问题,和小球走平衡木不一样,charctor
controller 是不可以对地面产生压力的,无论角色是否加了刚体,charactor controller 都
只具有自由下落,而不具有对地面压力。如果换成 box collider 等碰撞检测,上下楼梯角
色运动的时候很容易倒下。针对这个问题,做出了以下解决方案:
01
var speed = 10.0;
02
var gravity = 10.0;
03
var maxVelocityChange = 10.0;
04
var canJump = true;
05
var jumpHeight = 2.0;
06
private var grounded = false;
07
08
@script RequireComponent(Rigidbody, CapsuleCollider)
09
10
function Awake ()
11
{
12
rigidbody.freezeRotation = true;
13
rigidbody.useGravity = false;
14
}
15
16
function FixedUpdate ()
17
{
18
if (grounded)
19
{
20
// Calculate how fast we should be moving
21
var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
22
targetVelocity = transform.TransformDirection(targetVelocity);
23
targetVelocity *= speed;
24
25
// Apply a force that attempts to reach our target velocity
26
var velocity = rigidbody.velocity;
27
var velocityChange = (targetVelocity - velocity);
28
velocityChange.x = Mathf.Clamp(velocityChange.x, -
maxVelocityChange, maxVelocityChange);
29
velocityChange.z = Mathf.Clamp(velocityChange.z, -
maxVelocityChange, maxVelocityChange);
30
velocityChange.y = 0;
31
rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
32
33
// Jump
34
if (canJump && Input.GetButton("Jump"))
35
{Unity3D 教程手册
陈莽昆
- 粉丝: 19
- 资源: 291
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0