Aimbot-PPO/Aimbot-PPO-MultiScene/Assets/Script/InGame/Camera_Control.cs
Koha9 885dbb92e9 Add Enemy Change Button
Add Enemy Change Button. Tidy up Unity Script folder.
2022-09-06 23:01:55 +09:00

53 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera_Control : MonoBehaviour
{
public Transform Agent;
public Camera Cam;
public float MouseSensitivity = 100;
public float yRotation = 0.1f;//定义一个浮点类型的量记录围绕X轴旋转的角度
public float viewDistance = 100;
private float Mouse_X;
private float Mouse_Y;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;// 隐藏并且锁定鼠标
}
void Update()
{
//Mouse_X = Input.GetAxis("Mouse X") * MouseSensitivity * Time.deltaTime;
//Debug.Log(Input.GetAxis("Mouse X"));
//Mouse_Y = Input.GetAxis("Mouse Y") * MouseSensitivity * Time.deltaTime;
//yRotation = yRotation - Mouse_Y;
//xRotation值为正时屏幕下移当xRotation值为负时屏幕上移
//当鼠标向上滑动Mouse_Y值为正,xRotation-Mouse_Y的值为负,xRotation总的值为负屏幕视角向上滑动
//当鼠标向下滑动Mouse_Y值为负,xRotation-Mouse_Y的值为正,xRotation总的值为正屏幕视角向下滑动
//简单来说就是要控制鼠标滑动的方向与屏幕移动的方向要相同
//limit UP DOWN between -90 -> 90
//yRotation = Mathf.Clamp(yRotation, -90f, 90f);
//相机左右旋转时是以Y轴为中心旋转的上下旋转时是以X轴为中心旋转的
//Agent.Rotate(Vector3.up * Mouse_X);
//Vector3.up相当于Vector3(0,1,0),CameraRotation.Rotate(Vector3.up * Mouse_X)相当于使CameraRotation对象绕y轴旋转Mouse_X个单位
//即相机左右旋转时是以Y轴为中心旋转的此时Mouse_X控制着值的大小
//相机在上下旋转移动时,相机方向不会随着移动,类似于低头和抬头,左右移动时,相机方向会随着向左向右移动,类似于向左向右看
//所以在控制相机向左向右旋转时,要保证和父物体一起转动
//this.transform.localRotation = Quaternion.Euler(yRotation, 0, 0);
//this.transform指这个CameraRotation的位置,localRotation指的是旋转轴
//transform.localRotation = Quaternion.Eular(x,y,z)控制旋转的时候按照X-Y-Z轴的旋转顺规
//即以围绕X轴旋转x度围绕Y轴旋转y度围绕Z轴旋转z度
//且绕轴旋转的坐标轴是父节点本地坐标系的坐标轴
}
}