首页 > 编程语言 >unity3d相机跟随物体平滑移动(C#代码)

unity3d相机跟随物体平滑移动(C#代码)

时间:2023-01-05 13:02:11浏览次数:46  
标签:unity3d Vector3 C# float private 相机 wantedPosition currentY currentX

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,Vector3,C#,float,private,相机,wantedPosition,currentY,currentX
From: https://blog.51cto.com/u_8378185/5990730

相关文章

  • Unity3d碰撞器与触发器的区别详解(rigidbody移动和charactercontroller移动区别)
    Rigidbody或者charactercontroller移动才可以用collider的碰撞。正文:要产生碰撞必须为游戏对象添加刚体(Rigidbody)和碰撞器,刚体可以让物体在物理影响下运动。碰撞体是物理......
  • Vulnhub之Hacksudo Search靶机详细测试过程
    HacksudoSearch识别目标主机IP地址(kali㉿kali)-[~/Desktop/Vulnhub/Hacksudo_Search]└─$sudonetdiscover-ieth1-r192.168.56.0/24Currentlyscanning:192.1......
  • ThinkPHP多语言模块文件包含RCE复现详细教程
    漏洞描述:ThinkPHP在开启多语言功能的情况下存在文件包含漏洞,攻击者可以通过get、header、cookie等位置传入参数,实现目录穿越+文件包含,通过pearcmd文件包含这个trick即可实......
  • 2022 ICPC Gran Premio de Mexico Repechaje
    链接:https://codeforces.com/gym/104120A.AverageWalk#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;voidsolve(){intn;cin>>n......
  • CorsFilter跨域
    1、​​CORS跨域实现思路及相关解决方案​​2、​​spring跨域CORSFilter​​3、​​springboot设置cors跨域请求的两种方式​​4、​​CORSFilter解决前端跨域请求问题​......
  • Spring MVC
    1、​​SpringMVC—@RequestMapping原理讲解-1​​2、​​SpringMVC—@RequestMapping原理讲解-2​​3、​​SpringMVC判定返回view的依据​​4、​​SpringMVC源......
  • docker-reviewboard
    1、​​docker-reviewboard(让reviewboard安装、迁移更简单)​​2、​​ikatson​​/​​docker-reviewboard​​3、​​Docker入门之docker-compose​​4、​​docker​......
  • Elasticsearch学习笔记
    ​​最新ElasticSearch6实战教程​​​​全文搜索引擎Elasticsearch入门教程​​​​Elasticsearch学习,请先看这一篇!​​​​ElasticSearch简介​​​​Elasticsearch入门......
  • Java JUC学习笔记
    1、JUC简介在Java5.0提供了java.util.concurrent(简称JUC)包,在此包中增加了在并发编程中很常用的工具类,用于定义类似于线程的自定义子系统,包括线程池,异步IO和轻量......
  • NC14700 追债之旅
    题目链接题目题目描述小明现在要追讨一笔债务,已知有n座城市,每个城市都有编号,城市与城市之间存在道路相连(每条道路都是双向的),经过任意一条道路需要支付费用。小明一开始......