-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/Build/ | ||
/Builds/ | ||
/Library/ | ||
/[Oo]bj/ | ||
/Logs/ | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class BirdControllerOld : MonoBehaviour | ||
{ | ||
// rotation limits for flying | ||
public float minX = 60f; | ||
public float maxX = 120f; | ||
public float speed = .5f; | ||
|
||
// speed limits for birds | ||
public float lowSpeedLimit = 0.6f; | ||
public float highSpeedLimit = 1.4f; | ||
public float speedAdjustment = 0.01f; | ||
|
||
// movement for flying | ||
public float moveSpeed = 10f; | ||
public float internalMoveSpeed; | ||
public float moveSmoothing = 0.05f; | ||
private Vector3 zeroVec = Vector3.zero; | ||
|
||
// access to rigidbody and model | ||
public Rigidbody rb; | ||
public Transform model; | ||
public Transform animModel; | ||
|
||
// utility for flying rotation | ||
private float change; | ||
private float smooth; | ||
private float mouse; | ||
private float newX; | ||
private float newY; | ||
|
||
// utility for flying speed | ||
private float horizontalMove = 0.0f; | ||
|
||
// utility for stopping tilt & hovering | ||
public float tiltSmooth = 0.3f; | ||
private float sinCount = 0f; | ||
private Vector3 startingPos = Vector3.zero; | ||
public bool hovering = true; | ||
|
||
private bool Suppressed; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
internalMoveSpeed = moveSpeed; | ||
|
||
UiController.UiInteractionStart += () => | ||
{ | ||
Suppressed = true; | ||
Cursor.visible = true; | ||
Cursor.lockState = CursorLockMode.None; | ||
}; | ||
|
||
UiController.UiInteractionEnd += () => | ||
{ | ||
Suppressed = false; | ||
Cursor.visible = false; | ||
Cursor.lockState = CursorLockMode.Confined; | ||
}; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
if (Suppressed) | ||
{ | ||
rb.velocity = Vector3.zero; | ||
return; | ||
} | ||
|
||
// update flying velocity | ||
horizontalMove = Input.GetAxisRaw("Vertical"); | ||
if (horizontalMove < 0) horizontalMove = 0; | ||
|
||
// check if mouse is far enough from center to look up/down | ||
if (Input.mousePosition.y < Screen.height / 4) { | ||
newX += 2 * speed * (Mathf.Abs(Input.mousePosition.x - Screen.height / 2) / Screen.height); | ||
internalMoveSpeed = Mathf.Clamp(internalMoveSpeed + (horizontalMove * speedAdjustment), lowSpeedLimit, highSpeedLimit); | ||
} | ||
else if (Input.mousePosition.y > 3 * Screen.height / 4) { | ||
newX -= 2 * speed * (Mathf.Abs(Input.mousePosition.x - Screen.height / 2) / Screen.height); | ||
internalMoveSpeed = Mathf.Clamp(internalMoveSpeed - (horizontalMove * speedAdjustment), lowSpeedLimit, highSpeedLimit); | ||
} | ||
|
||
// check if mouse is far enough from center to look left/right | ||
if (Input.mousePosition.x < 8 * Screen.width / 20) { | ||
newY -= speed * 2 * (Mathf.Abs(Input.mousePosition.x - Screen.width / 2) / Screen.width); | ||
horizontalMove = 1; // force player to fly forward to turn | ||
} | ||
else if (Input.mousePosition.x > 12 * Screen.width / 20) { | ||
newY += speed * 2 * (Mathf.Abs(Input.mousePosition.x - Screen.width / 2) / Screen.width); | ||
horizontalMove = 1; // force player to fly forward to turn | ||
} | ||
|
||
// hide cursor again when clicking into game again | ||
// WILL NEED TO CHANGE THIS! to show cursor when decorating nest | ||
//if (Input.GetMouseButtonDown(0)) Cursor.visible = false; | ||
|
||
// avoid big scary numbers | ||
if (newX < -360) newX = 360 + newX; | ||
if (newY < 0) newY = 360 + newY; | ||
if (newY > 360) newY = newY - 360; | ||
|
||
// clamp x rotation | ||
newX = Mathf.Clamp(newX, minX, maxX); | ||
|
||
// update player rotation | ||
transform.rotation = Quaternion.Euler(newX, newY, transform.rotation.z); | ||
animModel.rotation = Quaternion.Euler(newX, newY, animModel.rotation.z); | ||
|
||
// handle movement logic | ||
Vector3 targetVelocity = transform.forward * horizontalMove * internalMoveSpeed; | ||
Vector3 curVelocity = rb.velocity; | ||
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref zeroVec, moveSmoothing); | ||
// make numbers nicer | ||
if (rb.velocity.magnitude < .01){ | ||
if (startingPos == Vector3.zero) { | ||
startingPos = this.transform.position; | ||
} | ||
hovering = true; | ||
rb.velocity = Vector3.zero; | ||
sinCount = sinCount + 0.01f; | ||
this.transform.position = new Vector3(startingPos.x, startingPos.y + (Mathf.Sin(sinCount) / 15), startingPos.z); | ||
} else { | ||
sinCount = 0; | ||
startingPos = Vector3.zero; | ||
hovering = false; | ||
} | ||
// check if decelerating to tilt model down | ||
if (horizontalMove == 0 && rb.velocity.magnitude != 0) { | ||
Quaternion target = Quaternion.Euler(-15, 0, 0); | ||
model.rotation = Quaternion.Slerp(model.rotation, target, tiltSmooth); | ||
} else { | ||
Quaternion target = Quaternion.Euler(0, 0, 0); | ||
model.rotation = Quaternion.Slerp(model.rotation, target, tiltSmooth); | ||
} | ||
} | ||
|
||
public bool GetHovering() { | ||
return hovering; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class FollowPlayerOld : MonoBehaviour | ||
{ | ||
public BirdControllerOld bird; | ||
public Transform target; | ||
public float smoothTime = 0.3f; | ||
public float lookSmoothTime = 0.1f; | ||
private Vector3 refVec = new Vector3(0, 0.5f, -1); | ||
private Vector3 velocity = Vector3.zero; | ||
|
||
void Update() | ||
{ | ||
// Define a target position above and behind the target transform | ||
Vector3 targetPosition = target.TransformPoint(refVec); | ||
if (targetPosition.y <= 0) targetPosition = new Vector3(targetPosition.x, 0.2f, targetPosition.z); | ||
|
||
// Smoothly move the camera towards that target position | ||
if (!bird.GetHovering()){ | ||
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime); | ||
} | ||
} | ||
|
||
void LateUpdate() | ||
{ | ||
if (!bird.GetHovering()) { | ||
Vector3 lookDirection = target.position - this.transform.position; | ||
lookDirection.Normalize(); | ||
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(lookDirection), lookSmoothTime * Time.deltaTime); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.