当前位置:网站首页>鼠标拖拽围绕某个物体旋转展示
鼠标拖拽围绕某个物体旋转展示
2022-06-25 22:19:00 【黑狗向前跑】
CameraController.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
float MouseX;
float MouseY;
//左右旋转速度
public float routateX;
//上下旋转速度
public float routateY;
//旋转速度
public float LerpRotateSpeed;
//目标点距离缩放
public float distanceScaleTargetValue;
//当前目标点距离缩放
public float distanceScaleCurrentValue;
//最小距离
public float minDistance;
//最大距离
public float maxDistance;
//限制最小旋转
public float minRotateYClampValue;
//限制旋转最大距离
public float maxRotateYClampValue;
//摄像机看向的位置
public Transform targetTrans;
//镜头缩放差值速度
public float lerpSpeed;
// Start is called before the first frame update
void Start()
{
MouseX = transform.eulerAngles.y;
MouseY = transform.eulerAngles.x;
distanceScaleCurrentValue = distanceScaleTargetValue;
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
MouseX += Input.GetAxis("Mouse X")*routateX;
//因为摄像机 向下旋转x值增加 向上旋转x减小 所以减去
MouseY -= Input.GetAxis("Mouse Y")*routateY;
MouseY = Mathf.Clamp(MouseY, minRotateYClampValue, maxRotateYClampValue);
}else if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
distanceScaleTargetValue += Input.GetAxis("Mouse ScrollWheel");
distanceScaleTargetValue = Mathf.Clamp(distanceScaleTargetValue, 0, 1);
}
}
private void FixedUpdate()
{
//左右转 设置MouseY的值 上下转设置MouseX的值
Quaternion quaternion = Quaternion.Euler(MouseY,MouseX , 0);
transform.rotation = Quaternion.Lerp(transform.rotation,quaternion,Time.deltaTime*LerpRotateSpeed);
Vector3 targetPosition = transform.rotation * new Vector3(0, 0,-GetCurrentPos())+targetTrans.position;
transform.position = targetPosition;
}
/// <summary>
/// 获取当前位置
/// </summary>
/// <returns></returns>
private float GetCurrentPos()
{
distanceScaleCurrentValue = Mathf.Lerp(distanceScaleCurrentValue,distanceScaleTargetValue,Time.deltaTime*lerpSpeed);
return minDistance + (maxDistance - minDistance) * distanceScaleTargetValue;
}
}
设置数值参考

边栏推荐
- P3052 [USACO12MAR]Cows in a Skyscraper G
- Frequently asked questions about redis
- 《SQL优化核心思想》
- 把控元宇宙产业的发展脉络
- smt贴片加工行业常见术语及知识汇总
- SMT贴片加工PCBA板清洗注意事项
- logstash丢弃没有精准匹配到文件名的日志数据
- 19c安装psu 19.12
- Literature research (IV): Hourly building power consumption prediction based on case-based reasoning, Ann and PCA
- 10.4.1、数据中台
猜你喜欢

idea设置mapper映射文件的模板

ASA如何配置端口映射及PAT

Mysql5.7.31自定义安装详细说明

把控元宇宙产业的发展脉络

Some common operation methods of array

Recommended system design

Notes on the method of passing items from the spider file to the pipeline in the case of a scratch crawler

86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)

正则表达式介绍及一些语法

Apache基金会正式宣布Apache InLong成为顶级项目
随机推荐
Apache基金会正式宣布Apache InLong成为顶级项目
毕业季 | 在不断探索中拟合最好的自己
Xiaohongshu microservice framework and governance and other cloud native business architecture evolution cases
11.1.1、flink概述_flink概述
farsync 简易测试
linux安装redis
ORA-01153 :激活了不兼容的介质恢复
huibian
性能领跑云原生数据库市场!英特尔携腾讯共建云上技术生态
Thrift getting started
Core ideas of SQL optimization
Reading notes on how to connect the network - hubs, routers and routers (III)
Network protocol: detailed explanation of redis protocol
The problem of low video memory in yolov5 accelerated multi GPU training
P3052 [USACO12MAR]Cows in a Skyscraper G
快手实时数仓保障体系研发实践
Frequently asked questions about redis
Ffmpeg version switching
文献调研(二):基于短期能源预测的建筑节能性能定量评估
Literature research (III): overview of data-driven building energy consumption prediction models