Skip to content

Commit

Permalink
16 Rotate Ship With Position & Throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Tristem committed Nov 10, 2017
1 parent 49f67e2 commit 507940b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
14 changes: 9 additions & 5 deletions Assets/Level 1.unity
Expand Up @@ -294,8 +294,12 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
speed: 20
xRange: 5.5
xRange: 5
yRange: 3
positionPitchFactor: -5
controlPitchFactor: -20
positionYawFactor: 5
controlRollFactor: -20
--- !u!1 &739114869
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -524,7 +528,7 @@ Camera:
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
field of view: 45
orthographic: 0
orthographic size: 5
m_Depth: -1
Expand Down Expand Up @@ -583,15 +587,15 @@ Prefab:
m_Modifications:
- target: {fileID: 4765256838916578, guid: 6b2f6692602716a49bcce1133bba67e3, type: 2}
propertyPath: m_LocalPosition.x
value: 0
value: -0.26
objectReference: {fileID: 0}
- target: {fileID: 4765256838916578, guid: 6b2f6692602716a49bcce1133bba67e3, type: 2}
propertyPath: m_LocalPosition.y
value: -1.23
value: -1.54
objectReference: {fileID: 0}
- target: {fileID: 4765256838916578, guid: 6b2f6692602716a49bcce1133bba67e3, type: 2}
propertyPath: m_LocalPosition.z
value: 6.6
value: 8.9
objectReference: {fileID: 0}
- target: {fileID: 4765256838916578, guid: 6b2f6692602716a49bcce1133bba67e3, type: 2}
propertyPath: m_LocalRotation.x
Expand Down
21 changes: 18 additions & 3 deletions Assets/Player.cs
Expand Up @@ -10,6 +10,13 @@ public class Player : MonoBehaviour {
[Tooltip("In m")] [SerializeField] float xRange = 5f;
[Tooltip("In m")] [SerializeField] float yRange = 3f;

[SerializeField] float positionPitchFactor = -5f;
[SerializeField] float controlPitchFactor = -20f;
[SerializeField] float positionYawFactor = 5f;
[SerializeField] float controlRollFactor = -20f;

float xThrow, yThrow;

// Use this for initialization
void Start () {

Expand All @@ -24,13 +31,21 @@ void Update ()

private void ProcessRotation()
{
transform.localRotation = Quaternion.Euler(-30f, 30f, 0f);
float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
float pitchDueToControlThrow = yThrow * controlPitchFactor;
float pitch = pitchDueToPosition + pitchDueToControlThrow;

float yaw = transform.localPosition.x * positionYawFactor;

float roll = xThrow * controlRollFactor;

transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}

private void ProcessTranslation()
{
float xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
float yThrow = CrossPlatformInputManager.GetAxis("Vertical");
xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
yThrow = CrossPlatformInputManager.GetAxis("Vertical");

float xOffset = xThrow * speed * Time.deltaTime;
float yOffset = yThrow * speed * Time.deltaTime;
Expand Down
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -89,3 +89,9 @@ Here are the lectures of the course for this section...
1. Experience order sensitivity in rotations.
2. Using `Quaternion.Euler()`.
3. Setting `localRotation` from code.

### 16 Rotate Ship With Position & Throw ###
1. Set pitch based on screen position.
2. Set pitch based also on control throw.
3. Set yaw based on screen position.
4. Set roll based on control throw.

1 comment on commit 507940b

@Bufftats
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work with the new input system. Makes the ship go diagonal.

Please sign in to comment.