- Home /
Question by
AnotherGuy_Evan · Feb 18, 2018 at 12:52 PM ·
controllerjoystickmouse control
Map Input.mousePosition to right stick of controller
I'm struggling with converting a script to take in the right joystick axes to control the mouse position. I'm not sure how to gain access to that.
Currently, this is what I have that controls player rotation.
public void Rotate()
{
Ray ray = viewCam.ScreenPointToRay(Input.mousePosition);
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float rayDistance;
if (groundPlane.Raycast(ray, out rayDistance))
{
Vector3 point = ray.GetPoint(rayDistance);
Debug.DrawLine(ray.origin, point, Color.red);
LookAt(point);
}
}
//Maintains rotation only on y-axis.
void LookAt(Vector3 lookPoint)
{
Vector3 heightCorrectedPoint = new Vector3(lookPoint.x, transform.position.y, lookPoint.z);
transform.LookAt(heightCorrectedPoint);
}
Comment