Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FPSControl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
unity
FPSControl
Commits
41421262
Commit
41421262
authored
4 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Fix initial orientation
parent
57155cfc
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
SmoothMouseLook.cs
+6
-5
6 additions, 5 deletions
SmoothMouseLook.cs
with
6 additions
and
5 deletions
SmoothMouseLook.cs
+
6
−
5
View file @
41421262
...
...
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using
UnityEngine
;
[
AddComponentMenu
(
"
Smooth
MouseLook "
)]
[
AddComponentMenu
(
"MouseLook "
)]
public
class
SmoothMouseLook
:
MonoBehaviour
{
// The speed at which we turn (Mouse Sensitivity)
...
...
@@ -58,8 +58,8 @@ public class SmoothMouseLook : MonoBehaviour
// first Child of type Camera. If none is found head = null
head
=
GetComponentInChildren
<
Camera
>().
transform
;
// Cache the orientation of body and head.
//
This errors if head (Camera Child) was not
found
// Cache the orientation of body and head.
This errors if head was not
// found
bodyStartOrientation
=
transform
.
localRotation
;
headStartOrientation
=
head
.
transform
.
localRotation
;
...
...
@@ -123,8 +123,9 @@ public class SmoothMouseLook : MonoBehaviour
// Compute rotations by rotating around a fixed axis (rotate yaw-degrees
// around the up direction for the body, and pitch degrees around the
// right direction for the head).
var
bodyRotation
=
Quaternion
.
AngleAxis
(
yaw
,
Vector3
.
up
);
var
headRotation
=
Quaternion
.
AngleAxis
(
pitch
,
Vector3
.
right
);
// Note: 90 deg need to be added, to get the initial orientation right
var
bodyRotation
=
Quaternion
.
AngleAxis
(
yaw
+
90
,
Vector3
.
up
);
var
headRotation
=
Quaternion
.
AngleAxis
(
pitch
+
90
,
Vector3
.
right
);
// Finally combine the rotations for body and head with the start rotations
transform
.
localRotation
=
bodyRotation
*
bodyStartOrientation
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment