2D game Z rotation question

Hi,

I have searched the forums in a couple of different ways but didnt see anything that could help me with this.

I have gone through the 2D tutorial and the FPS tutorials so far. After these, I got into a group trying to make a game using Unity (just a simple one for starters).

I am currently using Lerpz to practice with and I want to do something fairly specific. I want to make Lerpz’s head rotate up and down (so where he looks) in relation to the mouse pointer moving up and down.

I was able to make something like this work by creating my own capsule with a rigidbody. I then copied the mouselook.cs script from the FPS tutorial and modified it to use the Vector3.forward on the ‘Mouse Y’ section. That works exactly how I wnat it to. However, when I try to apply this to Lerpz’s head it does nothing and I just don’t understand why that would be.

Thanks for any help.

Mark

Hi, welcome to the forum!

Can you post the code you are using to control Lerpz’s head?

Surething, here is the code. It is just the typical mouselook script from the FPS tutorial with a slight modification to the mouseY section.

[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 rotationX = 0F;
float rotationY = 0F;

Quaternion originalRotation;

void Update ()
{
if (axes == RotationAxes.MouseXAndY)
{
// Read the mouse input axis
rotationX += Input.GetAxis(“Mouse X”) * sensitivityX;
rotationY += Input.GetAxis(“Mouse Y”) * sensitivityY;

rotationX = ClampAngle (rotationX, minimumX, maximumX);
rotationY = ClampAngle (rotationY, minimumY, maximumY);

Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);

transform.localRotation = originalRotation * xQuaternion * yQuaternion;
//transform.localRotation = originalRotation * yQuaternion;
}
else if (axes == RotationAxes.MouseX)
{
rotationX += Input.GetAxis(“Mouse X”) * sensitivityX;
rotationX = ClampAngle (rotationX, minimumX, maximumX);

Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
transform.localRotation = originalRotation * xQuaternion;
}
else
{
rotationY += Input.GetAxis(“Mouse Y”) * sensitivityY;
rotationY = ClampAngle (rotationY, minimumY, maximumY);

Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.forward);
transform.localRotation = originalRotation * yQuaternion;
}
}

void Start ()
{
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
originalRotation = transform.localRotation;
}

public static float ClampAngle (float angle, float min, float max)
{
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp (angle, min, max);
}
}

Have you definitely attached the script to the Lerpz head bone transform?

Well being as new as I am I guess that is what I am not sure about. I simply dragged the mouselook script and dropped it onto the piece of lerpz called head which was found under rootjoint/torso/shoulders.