当前位置:网站首页>Unity mouse controls the first person camera perspective
Unity mouse controls the first person camera perspective
2022-07-27 15:14:00 【A fool is a little proud】
Implementation of first person camera :
The horizontal distance when the mouse moves will determine the rotation angle of the camera in the horizontal direction , The axis of rotation should be In the world coordinate system y Axis
The distance in the vertical direction will make the camera rotate up and down , It should be around at this time In its own coordinate system x Axis rotate
Why not around the camera x Axis (transform.right), Change the rotating shaft and run it for a while
public class FirstPersonalCamera : MonoBehaviour { public float speed = 5; // Update is called once per frame void Update () { // The horizontal distance the mouse moves in this frame float x = Input.GetAxis("Mouse X"); // Around in world coordinates y Shaft rotation transform.Rotate(Vector3.up * x * speed, Space.World); // The vertical distance the mouse moves in this frame float y = Input.GetAxis("Mouse Y"); // Around their own x pivot transform.Rotate(Vector3.right * -y * speed); } }
When the mouse clicks , Move the mouse to make the camera angle rotate around the protagonist
public class CameraView : MonoBehaviour { Transform Player; private float x, y; public float rotateSpeed=5; // Use this for initialization void Awake() { Player = GameObject.FindGameObjectWithTag("Player").transform; // The camera looks at the player transform.LookAt(Player); } // Update is called once per frame void Update () { if (Input.GetMouseButton(1)) { // The horizontal distance the mouse moves in this frame x = Input.GetAxis("Mouse X"); // Around the player's point , World y Shaft rotation transform.RotateAround(Player.position, Vector3.up, x*rotateSpeed); // The vertical distance the mouse moves in this frame y = Input.GetAxis("Mouse Y"); // Around the player's point , Of the camera x Shaft rotation transform.RotateAround(Player.position, transform.right, y * rotateSpeed); } } }
边栏推荐
猜你喜欢

Nokia's patent business was hit for the first time, and Chinese enterprises are not so easy to knead

Unity 鼠标控制第一人称摄像机视角

Introduction of the connecting circuit between ad7606 and stm32

工具 - markdown编辑器常用方法

仅做两项修改,苹果就让StyleGANv2获得了3D生成能力
MOS管防止电源反接的原理

Skywalking distributed system application performance monitoring tool - medium

IJCAI 2022杰出论文公布,大陆作者中稿298篇拿下两项第一

CAN总线的EMC设计方案

周鸿祎:数字安全能力落后也会挨打
随机推荐
STM32 can communication filter setting problem
JMeter recording interface automation
Usage of countdownlatch in multithreaded environment
网络设备硬核技术内幕 路由器篇 7 汤普金森漫游网络世界(下)
网络设备硬核技术内幕 路由器篇 13 从鹿由器到路由器(上)
华云数据打造完善的信创人才培养体系 助力信创产业高质量发展
《剑指Offer》 链表反转
NEFU118 n!后面有多少个0【算术基本定理】
LeetCode 456. 132模式 单调栈/medium
网络设备硬核技术内幕 路由器篇 3 贾宝玉梦游太虚幻境 (中)
深圳市人力资源和社会保障局关于发放脱贫人口就业有关补贴的通知
【WORK】关于技术架构
网络设备硬核技术内幕 路由器篇 5 汤普金森漫游网络世界(上)
NEFU119 组合素数【算术基本定理】
网络设备硬核技术内幕 路由器篇 17 DPDK及其前传(二)
适配验证新职业来了!华云数据参与国家《信息系统适配验证师国家职业技能标准》编制
Kubernetes CNI 分类/运行机制
于不确定中见“安全感” 沃尔沃2022年中问道
网络设备硬核技术内幕 路由器篇 9 CISCO ASR9900拆解 (二)
Jmeter录制接口自动化
