Unity游戏开发入门指南
1. 角色移动与碰撞处理
在游戏开发中,角色移动是基础功能之一。当角色需要移动时,我们需要设置移动目标位置,并进行一些额外的操作。
1.1 角色移动设置
首先,让角色离开当前位置,将 movementDestination 设置为新位置。同时,使用 transform.LookAt(position) 让角色面向目标位置,这在使用实际角色模型时非常重要。
transform.LookAt(position);
接着,将位置稍微向上移动,并移动光标对象到目标位置上方一点,以指示移动目标。
1.2 碰撞处理
当角色碰撞到其他物体时,需要进行相应处理。 OnControllerColliderHit 方法可以实现这一功能。
void OnControllerColliderHit (ControllerColliderHit hit)
{
movementDestination = gameObject.transform.position;
movementDestination.y = 0.0f;
if (cursor != null) {
Vector3 cursorPosition = movementDestination;
cursorPosit
超级会员免费看
订阅专栏 解锁全文
516

被折叠的 条评论
为什么被折叠?



