当前位置:网站首页>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 !!!!
边栏推荐
- Tencent cloud database public cloud market ranks top 2!
- np. random. Shuffle and np Use swapaxis or transfer with caution
- 1. AVL tree: left-right rotation -bite
- Preliminary practice of niuke.com (9)
- Safe landing practice of software supply chain under salesforce containerized ISV scenario
- [JS component] custom select
- 高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
- 什么是依赖注入(DI)
- [论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
- 4. 对象映射 - Mapping.Mapster
猜你喜欢
Dj-zbs2 leakage relay
Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
Cve-2021-3156 vulnerability recurrence notes
The navigation bar changes colors according to the route
1.AVL树:左右旋-bite
1. AVL tree: left-right rotation -bite
A cool "ghost" console tool
Autowired注解用于List时的现象解析
5. Data access - entityframework integration
随机推荐
【js组件】自定义select
《4》 Form
《5》 Table
[binary tree] binary tree path finding
Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
张平安:加快云上数字创新,共建产业智慧生态
Jhok-zbg2 leakage relay
《2》 Label
5. 数据访问 - EntityFramework集成
数字化创新驱动指南
DOM node object + time node comprehensive case
Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
基于NCF的多模块协同实例
Tencent cloud database public cloud market ranks top 2!
分布式事务解决方案之TCC
app clear data源码追踪
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi
Leetcode (46) - Full Permutation
Photo selector collectionview