当前位置:网站首页>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 !!!!
边栏推荐
- 人体传感器好不好用?怎么用?Aqara绿米、小米之间到底买哪个
- Leakage relay jd1-100
- 漏电继电器JOLX-GS62零序孔径Φ100
- Photo selector collectionview
- 淘寶商品詳情頁API接口、淘寶商品列錶API接口,淘寶商品銷量API接口,淘寶APP詳情API接口,淘寶詳情API接口
- Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
- Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
- 纪念下,我从CSDN搬家到博客园啦!
- Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
- How does mapbox switch markup languages?
猜你喜欢

【js组件】date日期显示。

Pytest testing framework -- data driven

Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface
![[JS component] custom select](/img/9d/f7f15ec21763c40b9bb6a053d90ee4.jpg)
[JS component] custom select

Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting

Annotation初体验

1. AVL tree: left-right rotation -bite

Jhok-zbg2 leakage relay

pytest测试框架——数据驱动

消息队列:消息积压如何处理?
随机推荐
Educational Codeforces Round 22 B. The Golden Age
Dbsync adds support for mongodb and ES
高压漏电继电器BLD-20
K6EL-100漏电继电器
分布式事务介绍
Most commonly used high number formula
JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
Record a pressure measurement experience summary
Leakage relay jelr-250fg
AIDL 与Service
实现网页内容可编辑
《5》 Table
A cool "ghost" console tool
Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
“多模态”概念
Leakage relay jd1-100
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?
DJ-ZBS2漏电继电器
Timer create timer