【发布时间】:2014-07-14 19:23:09
【问题描述】:
所以我需要一种混合的第一人称 - 第三人称多人游戏控制器,我和我的朋友正在制作我们想要拥有第一人称体验的同时让其他玩家看到一个身体而不是第一人称控制器。但是我遇到了鼠标能够透过角色的脸看的错误,我想知道是否有一种方法可以让相机随着身体移动,头部向上和向下看。 有没有人有这个的代码。
- 详情
我们将相机连接到相机头,这是控制器的子对象,其中包含一些多人游戏的脚本。
控制器是附加了所有第一人称脚本的第三人称控制器。
编码“鼠标外观”C#(根据要求)
/// MouseLook rotates the transform based on the mouse delta.
/// Minimum and Maximum values can be used to constrain the possible rotation
/// To make an FPS style character:
/// - Create a capsule.
/// - Add the MouseLook script to the capsule.
/// -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
/// - Add FPSInputController script to the capsule
/// -> A CharacterMotor and a CharacterController component will be automatically added.
/// - Create a camera. Make the camera a child of the capsule. Reset it's transform.
/// - Add a MouseLook script to the camera.
/// -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)
[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
void Update ()
{
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
void Start ()
{
// Make the rigid body not change rotation
if (GetComponent<Rigidbody>())
GetComponent<Rigidbody>().freezeRotation = true;
}
}
【问题讨论】:
-
您使用什么编程语言?你已经标记了 java 和 C#...
-
不管是什么语言,您的问题都非常广泛,也许过于宽泛。你的代码在哪里?您的代码的哪一部分具体遇到了问题?您的问题本质上似乎是
"...does anyone have the code for that...",这不是本网站的运作方式。 -
你说,
"but i am having bugs with the mouse being able to look through the characters face..."——最好是描述你的错误,展示你的相关代码,然后从那里开始工作。 -
对不起,以后会做。已用代码更新帖子。
标签: java c# controller unity3d