噩梦5 camera跟随

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);

}

}

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-02 18:29:27

噩梦5 camera跟随的相关文章

噩梦5 屏幕跟随

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 ca

unity3d模仿魔兽世界鼠标对游戏操作

1.新建unity3d项目,在项目中导入CharacterController包.在游戏中创建Plane作为地面,把Plane的Tag设为Ground.创建Directional light照亮游戏世界.把第三人称控制器放到Plane上面,之后把挂载第三人称的脚本Remove掉,把它的Tag设为Player. 2.创建LookTargetPos脚本,把它挂载到第三人称控制器上.它的作用是当鼠标左键按下且按下的位置为Plane时,第三人称控制器朝向鼠标按下方向. using UnityEngine

ROS turtlebot_follower :让机器人跟随我们移动

ROS turtlebot_follower 学习 首先在catkin_ws/src目录下载源码,地址:https://github.com/turtlebot/turtlebot_apps.git 了解代码见注释(其中有些地方我也不是很明白) follower.cpp #include <ros/ros.h> #include <pluginlib/class_list_macros.h> #include <nodelet/nodelet.h> #include &

unity3d GL画线/物体跟随/坐标系转换

看见标题的人是不是在想... 一个小小的GL画线难吗? 一个小小的物体跟随难吗? 嗯,的确,一点不难.... 我一开始也是像你们那样想的,但是实际操作起来,还是和理论有区别的 写这个demo起因是这样的: 面试到了一家虚拟现实的公司,因为没有去公司 网上直接谈的,谈妥了hr估计是想看看我能不能胜任 给了我一张效果图,让我去实现画线的功能 咳咳,要求还是比较细致的,这里我们后面说 废话不多说,老规矩,先上效果图,然后直接进入主题 第一张是hr给我的图,第二张是我自己实现的 需求如下: 1.模型是旋

虚拟摇杆跟随鼠标

EasyTouch的joystick跟随鼠标 1 using UnityEngine; 2 using System.Collections; 3 4 public class JoystickPosControll : MonoBehaviour 5 { 6 7 public EasyJoystick m_EasyJoystick; 8 9 public Vector2 offset; 10 11 public Camera m_Camera; 12 13 public Vector2 bil

各种Camera

根据游戏类型的不一样,会需要各种各样的摄像机,下面将分享三种典型的摄像机类型:(1)地下城摄像机:(2)第三人称跟随摄像机:(3)鼠标控制旋转摄像机.将这些控制脚本拖动到场景的MainCamera上即可: 看向固定目标的Camera的基本实现,主要使用transform.LookAt函数来实现: public class LookAtCamera : MonoBehaviour { public GameObject target = null; void LateUpdate() { if (

Unity3D 利用FSM设计相机跟随实现

笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,国家专利发明人;已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解>电子工业出版社等. CSDN视频网址:http://edu.csdn.net/lecturer/144 FSM有限状态机前面已经跟读者介绍过,使用Unity3D引擎实现了动作状态以及技能切换,FSM使用的条件是有限个状态切换,我们可以将FSM应用到相机中,很多人会问在相机中如何使用FS

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

1.实现相机跟随主角运动 一种简单的方法是把Camera直接拖到Player下面作为Player的子物体,另一种方法是取得Camera与Player的偏移向量,并据此设置Camera位置,便能实现简单的相机跟随了. 这里我们选取第二种方法,首先给Camera添加一个脚本,取名为FollowPlayer,脚本很简单不做说明了 1 public class FollowPlayer : MonoBehaviour { 2 3 private Transform player; 4 private V

unity 常用的几种相机跟随

固定相机跟随 这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 1 using UnityEngine; 2 using System.Collections; 3 4 public class CameraFlow : MonoBehaviour 5 { 6 public Transform target; 7 private Vector3 offset; 8 // Use this for initialization 9 void Start() 10 {