[原]unity3D 相机跟随
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour {
public Transform target;
private Vector3 wantedPosition;
private float currentX;
private float currentY;
private float currentZ;
private float xVelocity = 0.0F;
private float yVelocity = 0.0F;
private float zVelocity = 0.0f;
private float distanceSnapTime = 0.1f;
// Update is called once per frame
void Update () {
Vector3 targetPos = target.position;
wantedPosition.x = targetPos.x;
wantedPosition.z = targetPos.z - 5f;//Vector3.forward*distance;
wantedPosition.y = targetPos.y -2f;// + heightAbovePlayer;
currentX = Mathf.SmoothDamp(currentX, wantedPosition.x, ref xVelocity, distanceSnapTime);
currentY = Mathf.SmoothDamp(currentY, wantedPosition.y, ref yVelocity, distanceSnapTime);
currentZ = Mathf.SmoothDamp(currentZ, wantedPosition.z, ref zVelocity, 0.5f);
transform.position = new Vector3(currentX,currentY,currentZ);
transform.LookAt(transform.position + new Vector3(0f,0.95f,1));
}
}
[原]unity3D 相机跟随的更多相关文章
- Unity3D 相机跟随主角移动
这里给主相机绑定一个脚本. 脚本写为: using UnityEngine; using System.Collections; public class camerafollow : MonoBeh ...
- Unity3D——相机跟随物体移动
public Transform target; public float moveSmooth=5f; Vector3 offset; void Start () { offset = transf ...
- unity3d简单的相机跟随及视野旋转缩放
1.实现相机跟随主角运动 一种简单的方法是把Camera直接拖到Player下面作为Player的子物体,另一种方法是取得Camera与Player的偏移向量,并据此设置Camera位置,便能实现简单 ...
- unity3D:游戏分解之角色移动和相机跟随
游戏中,我们经常会有这样的操作,点击场景中某个位置,角色自动移动到那个位置,同时角色一直是朝向那个位置移动的,而且相机也会一直跟着角色移动.有些游戏,鼠标滑动屏幕,相机就会围绕角色旋转. ...
- unity相机跟随Player常用方式
固定跟随,无效果(意义不大) public class FollowPlayer : MonoBehaviour { public Transform Player; private Vector3 ...
- SurvivalShooter学习笔记(一.相机跟随)
1.场景碰撞已好,地板需建一Quad去掉渲染留下碰撞,设置layer为Floor:用于建立摄像机朝向地面的射线,确定鼠标停留点,确定主角需要的朝向. 2.设置摄像机跟随主角: 本例中摄像机设置为正交模 ...
- unity 常用的几种相机跟随
固定相机跟随 这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collections; public c ...
- Unity中几种简单的相机跟随
#unity中相机追随 固定相机跟随,这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collectio ...
- unity_实用小技巧(相机跟随两个主角移动)
在两人对战的游戏中,有时候我们希望能看清楚两玩家的状态,这时我们需要让相机跟随玩家,可是我们不能让相机只跟随一个玩家移动,这时我们可以取两玩家的中点作为相机的位置.方法如下: public Trans ...
随机推荐
- 使用livereload实现自动刷新
livereload是一个web开发辅助工具,当我们修改完html.css和js的时候会自动刷新浏览器,解放码农的双手.这样在双屏切图.写js代码的时候会提高很多效率.livereload有很多版本, ...
- jqgrid 查询
<!DOCTYPE html> <html lang="en" lang="en" xmlns="http://www.w3.org ...
- HTML select 选中触发事件
$(function () { $("#cityidchange").change(function (data) { var cityid = $("#cityidch ...
- android尺子的自定义view——RulerView
项目中用到自定义尺子的样式: 原代码在github上找的,地址:https://github.com/QQabby/HorizontalRuler 原效果为 因为跟自己要使用的view稍有不同 所以 ...
- OAuth 授权
- Spring加载静态资源的方式
解决方法1:在web.xml里添加如下的配置 <servlet-mapping> <servlet-name>default</servlet-name> < ...
- mysql流程函数if之类
表名: salary ———————— userid | salary| ———————— 1 | 1000 2 | 2000 3 | 3000 4 | null ... IF(value, t, f ...
- e825. 当JSplitPane改变大小时分配空间
The weight of a split pane controls the behavior of the divider when the split pane is resized. If t ...
- Apache ZooKeeper
https://zookeeper.apache.org/ https://zh.wikipedia.org/wiki/Apache_ZooKeeper Apache ZooKeeper是Apache ...
- 基于Redis实现分布式锁以及任务队列
一.前言 双十一刚过不久,大家都知道在天猫.京东.苏宁等等电商网站上有很多秒杀活动,例如在某一个时刻抢购一个原价1999现在秒杀价只要999的手机时,会迎来一个用户请求的高峰期,可能会有几十万几百万的 ...