当前位置:网站首页>Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本
Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本
2022-07-02 09:45:00 【CoderZ1010】
目录
一、简介
RoamCameraController是用于漫游视角的相机控制脚本,同时支持Input System Package(New)和Input Manager(Old)新、旧两种输入系统。

该工具已经上传至我的框架SKFramework中的开发工具箱,如图所示。


框架已经在Github开源,地址:https://github.com/136512892/SKFramework

二、功能
1.键盘控制移动
通过键盘W、S、A、D、E、Q按键分别实现向前、后、左、右、上、下方向的移动:

2.视角拉近拉远
通过鼠标滚轮的滚动实现视角的拉近或拉远,作用等同于W、S按键:

3.视角旋转
通过按住鼠标右键并进行拖动实现视角的旋转:

通过设置verticalLimitMax、verticalLimitMin来限制在垂直方向上的旋转角度,以防止相机”倒立“。

4.视角聚焦
通过调用Focus函数实现视角的聚焦:
/// <summary>
/// 聚焦
/// </summary>
/// <param name="position">目标位置</param>
/// <param name="rotation">目标旋转</param>
/// <param name="duration">时长</param>
public void Focus(Vector3 position, Vector3 rotation, float duration);
5.活动区域限制
通过启用IsRangeClamped来实现活动范围的限制:

通过设置xMinValue...zMaxValue调整活动范围,如图所示,绿色线条形成的区域即活动的范围,相机运动不会超出该区域:

三、核心变量

toggle:控制系统的开关
isRangeClamped:是否启用活动区域限制
xMinValue、xMaxValue:在x轴上的活动区域范围,当isRangeClamped为true时起作用
yMinValue、yMaxValue:在y轴上的活动区域范围,当isRangeClamped为true时起作用
zMinValue、zMaxValue:在z轴上的活动区域范围,当isRangeClamped为true时起作用
translateSpeed:移动的速度
boost:加速系数,当按下键盘左边的Shift键时会加速移动
positionLerpTime:坐标插值到目标值所需时长
rotationLerpTime:旋转插值到目标值所需时长
mouseMovementSensitivity:鼠标灵敏度
mouseScrollMoveSpeed:鼠标滚轮滚动时视角拉近拉远的速度
invertScrollDirection:是否反转鼠标滚轮滚动时视角拉近拉远的方向
invertY:是否反转垂直方向上旋转的方向
verticalLimitMax:垂直方向上旋转的最大角度值
verticalLimitMin:垂直方向上旋转的最小角度值
边栏推荐
- [opencv] [image gradient]
- JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
- ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
- js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
- js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
- 国内首款、完全自主、基于云架构的三维CAD平台——CrownCAD(皇冠CAD)
- 难忘阿里,4面技术5面HR附加笔试面,走的真艰难真心酸
- Linear DP acwing 896 Longest ascending subsequence II
- Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
- Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
猜你喜欢

Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six

Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)

js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)

C modifier

JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))

Heap acwing 838 Heap sort

架构师必须了解的 5 种最佳软件架构模式

通过反射执行任意类的任意方法

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?

C operator
随机推荐
移动式布局(流式布局)
基于STM32的OLED 屏幕驱动
PXE installation UOS prompt NFS over TCP not available from 10 x.x.x
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Ntmfs4c05nt1g N-ch 30V 11.9a MOS tube, pdf
获取文件版权信息
ArrayList与LinkedList效率的对比
C#运算符
哈希表 AcWing 841. 字符串哈希
Mongodb redis differences
线性DP AcWing 895. 最长上升子序列
Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution
[opencv learning] [image filtering]
Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
moon
C#修饰符
Rust search server, rust quick service finding tutorial
Counting class DP acwing 900 Integer partition
百款拿来就能用的网页特效,不来看看吗?
Heap acwing 839 Simulated reactor