您的位置:首页 > 其它

实现宠物跟随移动效果

2017-08-29 20:22 826 查看
宠物身上的脚本

using UnityEngine;
using System.Collections;

public class Follow : MonoBehaviour {
//宝宝要跟随的目标
public Transform target;
//宝宝跟随目标的偏移量
public Vector3 offset;
//宠物在玩家后的距离
public float backDistance = 2;
//高度
public float topDistance = 2;

//在LateUpdate中进行物理
void LateUpdate()
{
//设置一个偏移量
offset = -target.forward * backDistance + target.up * topDistance;
//使用插值,让宠物有一个平滑的移动
//重点;跟随效果的实现
transform.position = Vector3.Lerp(transform.position, target.position + offset,Time.deltaTime);
//让宠物的旋转和玩家的旋转保持一致
transform.rotation = target.rotation;
}
}


这里没有写玩家移动

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  移动 脚本