一.第三人称视角 _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. 树莓派 Raspbian

    备注,从右往左分别是:无线鼠标一个, HDMI转VGA接口一个,网线一根,小米充电宝电源线一个.树莓派Pi 3 一台,包括读卡器一个+32G class10 SD卡一块.最后俩个U盘作为备用里面有Ar ...

  2. [译文]casperjs 的API-casper模块

    Casper class: 可以通过这个模块的create()方法来获取这个模块的一个实例,这是最容易的: var casper = require('casper').create(); 我们也可以 ...

  3. POJ2259 Team Queue (JAVA)

    第一次TLE,对每个group重新设置Queue中定位,定位到每个group的最后一个元素,但WA 经过检查,DEQUEUE时没有根据情况重新计算group,插入时没有根据情况重新给last赋值 贴A ...

  4. SpringMVC的JSP页面中中EL表达式不起作用的问题解决

    原文地址:https://blog.csdn.net/sinat_35512245/article/details/53611663

  5. 51nod1238. 最小公倍数之和 V3(数论)

    题目链接 https://www.51nod.com/Challenge/Problem.html#!#problemId=1238 题解 本来想做个杜教筛板子题结果用另一种方法过了...... 所谓 ...

  6. NOI Linux学习

    打开终端: cd (目录名)//进入该目录的终端 cd ..//退出该目录,返回上一层. 修改用户名 密码: 修改密码: passwd//直接修改root密码 passwd (用户名)//修改该用户的 ...

  7. js对函数参数的封装

    对函数参数的封装 一个原始函数有n个参数,用wrap对函数进行封装,生成一个新的函数,当给它传入参数数量为n的时候,将执行原始函数,否则不执行 //函数封装 function wrap(func){ ...

  8. <div>标签输入文字

    @*输入框,contenteditable="true"使能div可以输入文字*@ <div contenteditable="true" class=& ...

  9. 分分钟钟学会Python - 基础

    1.常见操作系统 1.windows xp/win7/win/10/window server 2.linux centos,图形化界面差 ubuntu,个人开发(图形化比较好) redhat,企业级 ...

  10. JDK,JRE,JVM的基础理解

    1.JVM -- java virtual machine JVM就是我们常说的java虚拟机,它是整个java实现跨平台的 最核心的部分,所有的java程序会首先被编译为.class的类文件,这种类 ...