Skip to content

Instantly share code, notes, and snippets.

@cubed2d
Forked from SamFZGames/gist:4bce10a255f90bc72921
Last active August 29, 2015 14:19
Show Gist options
  • Save cubed2d/8be35b055e1b5278edcb to your computer and use it in GitHub Desktop.
Save cubed2d/8be35b055e1b5278edcb to your computer and use it in GitHub Desktop.
In PlayerScript:
// Sprite direction
if (xInput > 0) {
transform.rotation = Quaternion.Euler (0, 0, 0);
} else if (xInput < 0) {
transform.rotation = Quaternion.Euler (0, 180, 0);
}
// Aiming
float direction = xInput > 0 ? 1f : -1f;
if (lookingUp) {
if (xInput == 0) {
zapperAngle = Quaternion.Euler (0, 0, 0); // no rotaiton as were rotating a vector pointing up
} else {
zapperAngle = Quaternion.Euler (0, 0, 45 * direction);
}
} else if ( yInput < 0 && ( !IsGrounded() || aimLock ) ) {
if ( xInput == 0 && !aimLock ) {
zapperAngle = Quaternion.Euler (0, 0, 180);
} else {
zapperAngle = Quaternion.Euler (0, 0, 135*direction);
}
} else {
zapperAngle = Quaternion.Euler (0, 0, 90 * direction);
}
In CameraScript:
// Aiming the camera with the gun
aimAngle = PlayerScript.instance.zapperAngle;
aimOffset = PlayerScript.instance.zapperAngle * new Vector3(0, 2, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment