当前位置:网站首页>Unity keeps the camera behind and above the player
Unity keeps the camera behind and above the player
2022-07-07 05:34:00 【iiiiiiimp】
Unity Let the camera follow the player all the time
Write it at the front
There is a need , Let the camera follow the player all the time , And rotate with the player's rotation .
Camera follow effect

Principle explanation
1、 Use the coordinates of the camera to get the coordinates of the player to get the upward and backward distance of the camera relative to the player 
The corresponding code
camera2PlayerDir = this.transform.position-playerTransform.position;
playerUp = camera2PlayerDir.y;
playerBack= camera2PlayerDir.z;
2、 Use the position after the player moves + The upward distance of the camera relative to the player ×Vector3.up+ The backward distance of the camera relative to the player ×playerTransform.forward( The current direction of the player ) You can get the position where the camera is going to move 
The corresponding code
targetPosition = playerTransform.position + Vector3.up * playerUp + playerTransform.forward * playerBack;
3、 Use Vector3.Lerp Make the camera move more balanced . The degree of camera rotation is the degree of player rotation .
Randomly generate enemy effect

Principle explanation
In order that the generated enemies will not overlap , That is, two tanks collide in the same place , Need to use Physics.CheckSphere This function .
First, the map boundary and the ground Layer Set up Plane
Then use... In the code LayerMask layerMask = ~LayerMask.GetMask("Plane"); Let the ray not detect Plane Objects at this level
LayerMask layerMask = ~LayerMask.GetMask("Plane");// Equivalent to ~(1<<6)
do {
randomX = Random.Range(-createX, createX);
randomY = Random.Range(-createY, createY);
} while (Physics.CheckSphere(new Vector3(randomX,0,randomY),createRadius,layerMask));
Written in the back
learn Unity Math is really important !!!!
边栏推荐
- Creation and use of thread pool
- Mysql database learning (8) -- MySQL content supplement
- [question] Compilation Principle
- 淘宝商品详情页API接口、淘宝商品列表API接口,淘宝商品销量API接口,淘宝APP详情API接口,淘宝详情API接口
- [optimal web page width and its implementation] [recommended collection "
- ThinkPHP Association preload with
- JHOK-ZBL1漏电继电器
- 论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
- App clear data source code tracking
- 漏电继电器JD1-100
猜你喜欢

1.AVL树:左右旋-bite

论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】

Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET

漏电继电器LLJ-100FS

Egr-20uscm ground fault relay

Leakage relay jd1-100

分布式事务解决方案之2PC

Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi

5. Data access - entityframework integration
![[binary tree] binary tree path finding](/img/34/1798111e9a294b025806a4d2d5abf8.png)
[binary tree] binary tree path finding
随机推荐
Jhok-zbl1 leakage relay
AIDL 与Service
[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
Tablayout modification of customized tab title does not take effect
JVM(二十) -- 性能监控与调优(一) -- 概述
How does mapbox switch markup languages?
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface
nodejs获取客户端ip
【js组件】date日期显示。
Initial experience of annotation
Educational Codeforces Round 22 B. The Golden Age
删除文件时提示‘源文件名长度大于系统支持的长度’无法删除解决办法
利用OPNET进行网络单播(一服务器多客户端)仿真的设计、配置及注意点
阿里云的神龙架构是怎么工作的 | 科普图解
Dj-zbs2 leakage relay
数字化创新驱动指南
张平安:加快云上数字创新,共建产业智慧生态
消息队列:如何确保消息不会丢失
Digital innovation driven guide