当前位置:网站首页>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 !!!!
边栏推荐
- Taobao store release API interface (New), Taobao oauth2.0 store commodity API interface, Taobao commodity release API interface, Taobao commodity launch API interface, a complete set of launch store i
- 5阶多项式轨迹
- Leakage relay jelr-250fg
- Intelligent annotation scheme of entity recognition based on hugging Face Pre training model: generate doccano request JSON format
- Pytest testing framework -- data driven
- 数字化如何影响工作流程自动化
- K6el-100 leakage relay
- Getting started with DES encryption
- 删除文件时提示‘源文件名长度大于系统支持的长度’无法删除解决办法
- Digital innovation driven guide
猜你喜欢
一条 update 语句的生命经历
Photo selector collectionview
Two person game based on bevy game engine and FPGA
漏电继电器JD1-100
Mysql database learning (8) -- MySQL content supplement
论文阅读【Sensor-Augmented Egocentric-Video Captioning with Dynamic Modal Attention】
Torch optimizer small parsing
数字化创新驱动指南
阿里云的神龙架构是怎么工作的 | 科普图解
消息队列:如何确保消息不会丢失
随机推荐
High voltage leakage relay bld-20
JHOK-ZBG2漏电继电器
淘宝商品详情页API接口、淘宝商品列表API接口,淘宝商品销量API接口,淘宝APP详情API接口,淘宝详情API接口
Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET
Aidl and service
Simulate thread communication
EGR-20USCM接地故障继电器
Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
利用OPNET进行网络任意源组播(ASM)仿真的设计、配置及注意点
Taobao Commodity details page API interface, Taobao Commodity List API interface, Taobao Commodity sales API interface, Taobao app details API interface, Taobao details API interface
How can professional people find background music materials when doing we media video clips?
Leakage relay jd1-100
How digitalization affects workflow automation
A cool "ghost" console tool
项目经理如何凭借NPDP证书逆袭?看这里
Pytest testing framework -- data driven
[PHP SPL notes]
漏电继电器JD1-100
English语法_名词 - 所有格
Talk about mvcc multi version concurrency controller?