unity3d之相机跟随人物
一.第三人称视角 _1
先设置好相机与玩家之间的角度

给相机添加代码
using UnityEngine;
using System.Collections; namespace CompleteProject
{
public class CameraFollow : MonoBehaviour
{
public Transform target; // The position that that camera will be following.
public float smoothing = 5f; // The speed with which the camera will be following. Vector3 offset; // The initial offset from the target. void Start ()
{
// Calculate the initial offset.
offset = transform.position - target.position;
} void FixedUpdate ()
{
// Create a postion the camera is aiming for based on the offset from the target.
Vector3 targetCamPos = target.position + offset; // Smoothly interpolate between the camera's current position and it's target position.
//相机平滑的移动到目标位置,插值
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}
}
二、第三人称视角_2,可自己根据游戏效果调节位置
在inspector面板修改mHeight与mDistance值即可
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class FollowCamera : MonoBehaviour
{
public Transform mTarget; //相机的跟随目标
public float mHeight=8f;
public float mDistance=6f;
public float interpolation = 20.0f;
public Space space = Space.World; // Use this for initialization
void Start ()
{ } // Update is called once per frame
void LateUpdate ()
{
if (mTarget)
{
Vector3 dest = Vector3.zero;
switch (space)
{
case Space.World://以世界为中心
dest = mTarget.position + Vector3.up * mHeight - Vector3.forward * mDistance;
break;
case Space.Self://玩家为中心,一般用不到可省略switch
dest = mTarget.position + mTarget.up * mHeight - mTarget.forward * mDistance;
break;
default:
break;
}
transform.position = Vector3.Lerp(transform.position, dest, interpolation);
transform.LookAt(mTarget.position);
}
}
}
unity3d之相机跟随人物的更多相关文章
- unity相机跟随Player常用方式
固定跟随,无效果(意义不大) public class FollowPlayer : MonoBehaviour { public Transform Player; private Vector3 ...
- Unity3d学习 相机的跟随
最近在写关于相机跟随的逻辑,其实最早接触相机跟随是在Unity官网的一个叫Roll-a-ball tutorial上,其中简单的涉及了关于相机如何跟随物体的移动而移动,如下代码: using Unit ...
- unity3d简单的相机跟随及视野旋转缩放
1.实现相机跟随主角运动 一种简单的方法是把Camera直接拖到Player下面作为Player的子物体,另一种方法是取得Camera与Player的偏移向量,并据此设置Camera位置,便能实现简单 ...
- unity3D:游戏分解之角色移动和相机跟随
游戏中,我们经常会有这样的操作,点击场景中某个位置,角色自动移动到那个位置,同时角色一直是朝向那个位置移动的,而且相机也会一直跟着角色移动.有些游戏,鼠标滑动屏幕,相机就会围绕角色旋转. ...
- SurvivalShooter学习笔记(一.相机跟随)
1.场景碰撞已好,地板需建一Quad去掉渲染留下碰撞,设置layer为Floor:用于建立摄像机朝向地面的射线,确定鼠标停留点,确定主角需要的朝向. 2.设置摄像机跟随主角: 本例中摄像机设置为正交模 ...
- unity 常用的几种相机跟随
固定相机跟随 这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collections; public c ...
- Unity中几种简单的相机跟随
#unity中相机追随 固定相机跟随,这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collectio ...
- unity_实用小技巧(相机跟随两个主角移动)
在两人对战的游戏中,有时候我们希望能看清楚两玩家的状态,这时我们需要让相机跟随玩家,可是我们不能让相机只跟随一个玩家移动,这时我们可以取两玩家的中点作为相机的位置.方法如下: public Trans ...
- Unity相机跟随
固定相机跟随 这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collections; public c ...
随机推荐
- AutoCAD.Net圆弧半径标注延长线
#region 注册RegApp public static void CheckRegApp(string regapptablename) { Database db = HostApplicat ...
- VMware虚拟机中如何配置静态IP
我们首先说一下VMware的几个虚拟设备 VMnet0:用于虚拟桥接网络下的虚拟交换机 VMnet1:用于虚拟Host-Only网络下的虚拟交换机 VMnet8:用于虚拟NAT网络下的虚拟交换机 VM ...
- mysqldump导出数据不带时区信息的问题
今天在导出数据时,发现所有timestamp字段都不带时区信息,因为我在东8区,导出的数据中所有时间都提早了8个小时 首先先看表的字段和数据 CREATE TABLE IF NOT EXISTS `a ...
- ubuntu和centos 编译安装nginx及常用命令
转自http://www.cnblogs.com/piscesLoveCc/p/5794926.html 一. ubuntu安装 1. 安装依赖库 安装gcc g++的依赖库 ubuntu平台可以使用 ...
- luogu P1518 两只塔姆沃斯牛 The Tamworth Two
luogu P1518 两只塔姆沃斯牛 The Tamworth Two 题目描述 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为(牛和John). 追击在 ...
- ajax跨域请求问题
ajax是不允许跨域请求的,今天在使用bootstap-table的时候,data-url使用的地址是绝对地址,而非相对地址,因此在载入数据的时候就出错了. 启动的时候使用是 http://127.0 ...
- 51 Nod 1050 dp
1050 循环数组最大子段和 1 秒 131,072 KB 10 分 2 级题 N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的连 ...
- selenium(python)登录时账号密码错误提示语
selenium(python)登录时账号密码错误提示语的获取 可以用text
- 深入理解计算机系统10——系统级I/O
系统级I/O 输入/输出 是在主存和外部设备之间拷贝数据的过程. 外部设备可以是:磁盘驱动器.终端和网络. 输入和输出都是相对于主存而言的. 输入是从I/O设备拷贝数据到主存.输出时从主存拷贝数据到I ...
- element-ui table多选CheckBox参数解析
element-UI里的table表格与多选框CheckBox的组合很常用,官网也给了很多参数,自己总结了一下,方便日后使用 1.简易用法,没有附加的功能 要在表格里使用CheckBox很简单,只需设 ...