这次要完成Camera跟随Player移动,

首先考虑Camera的跟随目标target和平滑移动速度smothing再考虑Camera与Player的偏移量(就是Camera与Player有一个永恒的长度)

目标位置和平滑移动速度

public Transform target;

public float smothing = 5f;

偏移量

Vector3 offset;

设置偏移量

void Start () {

offset = transform.position - target.position;

}

随着Player的移动,摄像机需要移动到新的位置

Vector3 targetCampos = target.position + offset;

得到Camera要移动的位置后

transform.position=Vector3.Lerp(transform.position,targetCampos,smothing* Time.deltaTime);

则完整代码

 using UnityEngine;
using System.Collections; public class CameraFloor : MonoBehaviour {
public Transform target;
public float smothing = 5f;
Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position - target.position;
}
// Update is called once per frame
void FixedUpdate () {
Vector3 targetCampos = target.position + offset;
transform.position = Vector3.Lerp(transform.position, targetCampos, smothing * Time.deltaTime);//摄像机自身位置到目标位置
}
}

小白的Unity5之路(二)镜头平滑跟随角色的更多相关文章

  1. 小白的Unity5之路(一)

    Player移动: public float speed = 6f; Vector3 movement; Rigidbody playerRididbody; void FixedUpdate () ...

  2. 我的VSTO之路(二):VSTO程序基本知识

    原文:我的VSTO之路(二):VSTO程序基本知识 开始之前,首先我介绍一下我的开发环境:VS2010 + Office 2010,是基于.Net framework 4.0和VSTO 4.0.以下的 ...

  3. 一只代码小白git托管路上的二三事

    [经验]一只代码小白git托管路上的二三事 写在前面的话 寒假的时候,娄老师给我们布置了代码托管的作业,并要求把托管地址发给学委.因假期的时候没有带电脑回家,所以只是在手机上草草注册了,也稀里糊涂就将 ...

  4. 小白的springboot之路(一)、环境搭建、第一个实例

    小白的springboot之路(一).环境搭建.第一个实例 0- 前言 Spring boot + spring cloud + vue 的微服务架构技术栈,那简直是爽得不要不要的,怎么爽法,自行度娘 ...

  5. Python小白的发展之路之Python基础(二)

    列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表.元组操作 (1)列表 列表是可变的(mutable)--可以改变列表的内容,这不同于字符串和元组,字符串和元组都是不 ...

  6. Python小白的发展之路之Python基础(二)【字符串、列表、集合、文件操作】

    列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表.元组操作 (1)列表 列表是可变的(mutable)——可以改变列表的内容,这不同于字符串和元组,字符串和元组都是不 ...

  7. 小白学习python之路(二):安装开发工具

    引言 上一章我们安装配置了python3.7,这一章我们安装python的开发工具,我用的pycharm2019 安装 工具连接:https://u20538204.ctfile.com/fs/205 ...

  8. 小白的springboot之路(二)、集成swagger

    0-前言 现在的项目开发,基本都是前后端分离,后端专注于API接口开发,都需要编写和维护API接口文档.如果你还在用Word来编写接口文档,那你就out了,这个时候,当当当当~神兵利器swagger隆 ...

  9. 小白的springboot之路(十二)、集成log4j2日志

    0.前言 日志记录对系统来说必不可少,spring boot中常用的日志组件有log4j.logback.log4j2,其中logback是spring boot默认的,已自带:选用log4j2就可以 ...

随机推荐

  1. group by 一条语句实现多条语句的效果

    --一个sql 使用 group by 实现 4个 sql 的效果 select ProjectNumber,ClientName,jx,sf,sum(count) as TotalCount fro ...

  2. 执行系统命令,subprocess使用说明

    os.system('ls -l') #只执行命令,不能将结果赋予变量 os.system('mkdir test')  #创建test目录 files = os.popen('ls -l').rea ...

  3. vector中删除的注意事项

    erase的函数原型有两种形式: iterator erase(iterator position); iterator erase(iterator first, iterator last); 例 ...

  4. Homebrew 安装 MySQL

    安装 Homebrew brew doctor 确认 brew 在正常工作 brew update 更新包 brew install mysql 安装 MySQL ​ ==> Downloadi ...

  5. codeforces 388D Fox and Perfect Sets(线性基+数位dp)

    #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mp mak ...

  6. BT提权wind2008R2

    昨天中午打开电脑,对着菜刀在那翻啊翻,找到一个64bit的os. 因为这个ip不在曾经提权过的主机列表里面,心想这应该是个低权限的网站,顺手打个whoami试试,结果给我返回了"nt aut ...

  7. pip install lxml mysql-python error

    问题0: 在安装 mysql-python时,会出现: sh: mysql_config: not found Traceback (most recent call last): File &quo ...

  8. Angular4 @HostBinding @HostListener

    host属性 @Component({ selector: 'jhi-project', templateUrl: './project.html', styleUrls: [], host: { ' ...

  9. 高性能 Socket 组件 HP-Socket v3.2.1-RC3 公布

    HP-Socket 是一套通用的高性能 TCP/UDP Socket 组件,包括服务端组件.client组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统.提供 C/C+ ...

  10. 【[SDOI2017]序列计数】

    感觉自己的复杂度感人 大概是\(O(p*\pi(m)+p^3logn)\) 还是能过去的 我们看到这么大的数据范围还是应该先想一想暴力怎么写 显然我们可以直接暴力\(dp\) 设\(dp[i][j]\ ...