一.第三人称视角 _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之相机跟随人物的更多相关文章

  1. unity相机跟随Player常用方式

    固定跟随,无效果(意义不大) public class FollowPlayer : MonoBehaviour { public Transform Player; private Vector3 ...

  2. Unity3d学习 相机的跟随

    最近在写关于相机跟随的逻辑,其实最早接触相机跟随是在Unity官网的一个叫Roll-a-ball tutorial上,其中简单的涉及了关于相机如何跟随物体的移动而移动,如下代码: using Unit ...

  3. unity3d简单的相机跟随及视野旋转缩放

    1.实现相机跟随主角运动 一种简单的方法是把Camera直接拖到Player下面作为Player的子物体,另一种方法是取得Camera与Player的偏移向量,并据此设置Camera位置,便能实现简单 ...

  4. unity3D:游戏分解之角色移动和相机跟随

          游戏中,我们经常会有这样的操作,点击场景中某个位置,角色自动移动到那个位置,同时角色一直是朝向那个位置移动的,而且相机也会一直跟着角色移动.有些游戏,鼠标滑动屏幕,相机就会围绕角色旋转. ...

  5. SurvivalShooter学习笔记(一.相机跟随)

    1.场景碰撞已好,地板需建一Quad去掉渲染留下碰撞,设置layer为Floor:用于建立摄像机朝向地面的射线,确定鼠标停留点,确定主角需要的朝向. 2.设置摄像机跟随主角: 本例中摄像机设置为正交模 ...

  6. unity 常用的几种相机跟随

    固定相机跟随 这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collections; public c ...

  7. Unity中几种简单的相机跟随

    #unity中相机追随 固定相机跟随,这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collectio ...

  8. unity_实用小技巧(相机跟随两个主角移动)

    在两人对战的游戏中,有时候我们希望能看清楚两玩家的状态,这时我们需要让相机跟随玩家,可是我们不能让相机只跟随一个玩家移动,这时我们可以取两玩家的中点作为相机的位置.方法如下: public Trans ...

  9. Unity相机跟随

    固定相机跟随 这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collections; public c ...

随机推荐

  1. 解决方法:配置群集时# gem install redis 报错:Unable to require openssl, install OpenSSL and rebuild ruby

    问题:前面已经在/usr/local/src安装了ruby-2.3.0.tar.gz.rubygems-2.4.2.tar.gz.在配置 redis-3.1.1 群集中,使用gem install 安 ...

  2. [AIR] 对存储器(Storage Volume)监听

    AIR 2.0及以上提供了对系统的存储器信息访问和监听的API.通过这些API,你不仅可以访问到硬盘文件系统,同时还可以监听通过USB或火线进行连接的移动存储设备,例如移动硬盘和以存储方式连接到计算机 ...

  3. shell中tr的用法

    转自http://blog.csdn.net/zhuying_linux/article/details/6825568 tr(translate缩写)主要用于删除文件中的控制字符,或进行字符转换.语 ...

  4. software installing

    <1>.Apache防火墙配置 firewall-cmd --add-service=http firewall-cmd --add-service=https 防火墙通过80和443端口 ...

  5. helloweblogic 官方qq群欢迎加入!

    点击加入helloweblogic 官方qq群,大家一起进行中间件技术交流,问题交流,互相帮忙互相学习. 我的网易博客地址:http://fm928.blog.163.com 收到网易博客的邮件,以后 ...

  6. 【linux】如何查看文件的创建、修改时间

    本篇博文旨在介绍Linux下查看文件时间的方法:并介绍如何使用touch指令来进行文件时间的创建以及修改 如何查看文件的时间信息利用stat指令查看文件信息 三种时间的介绍ATime ——文件的最近访 ...

  7. redis中算法之——MurmurHash2算法

    MurmurHash算法由Austin Appleby发明于2008年,是一种非加密hash算法,适用于基于hash查找的场景.murmurhash最新版本是MurMurHash3,支持32位,64位 ...

  8. (转)Http状态码301和302概念简单区别及企业应用案例

    Http状态码301和302的区别及企业应用案例 原文:http://blog.51cto.com/oldboy/1774260 1.什么是301重定向? 301重定向/跳转一般,表示本网页永久性转移 ...

  9. 【wordpress】wordpress自定义主题

    wordpress每个主题至少要有这两个文件 – style.css 和 index.php. index.php 告诉主题中所有的元素如何布局; style.css 则告诉主题中所有的元素该如何展示 ...

  10. Golang教程:函数、变参函数

    函数是完成一个特定任务的代码块.一个函数接受输入,对输入进行一些运算并产生输出. 函数声明 在 Go 中声明一个函数的语法为: func functionname(parametername type ...