Added sounds, fixed some bugs

added a sound for the tambourine, spider web, and background music.\n- finally fixed the web animation\n- added Sir Jacques to the web animation\n- changed the way the fire point tracks the grapple
This commit is contained in:
slevy14
2023-04-19 17:24:55 -07:00
parent cb059613f9
commit 686bc2528b
19 changed files with 629 additions and 149 deletions

View File

@@ -62,12 +62,25 @@ public class PlayerBehavior : MonoBehaviour
_hInput = value.Get<Vector2>().x;
if (_hInput < 0)
{
// if (forward != -1) { // if character hasnt already flipped
// FlipScale();
// }
forward = -1;
}
else if (_hInput > 0)
{
// if (forward != 1) { // if character hasnt already flipped
// FlipScale();
// }
forward = 1;
}
}
void FlipScale() { // DOENST WORK RIGHT
Vector3 currentScale = this.gameObject.transform.localScale;
currentScale.x *= -1;
this.gameObject.transform.localScale = currentScale;
}
void ThrowTambourine() {

View File

@@ -16,6 +16,7 @@ public class TambourineBehavior : MonoBehaviour {
private GameObject player;
public bool pinned = false;
public AudioSource tambourineHitSound;
void Awake() {
@@ -40,9 +41,10 @@ public class TambourineBehavior : MonoBehaviour {
// this.gameObject.transform.position = col.transform.position;
timeLerped += Time.deltaTime;
this.gameObject.transform.position = Vector2.Lerp(this.gameObject.transform.position, collidedObject.transform.position, timeLerped/timeToLerp);
if (this.gameObject.transform.position.x == collidedObject.transform.position.x && this.gameObject.transform.position.y == collidedObject.transform.position.y) {
if (this.gameObject.transform.position.x == collidedObject.transform.position.x && this.gameObject.transform.position.y == collidedObject.transform.position.y && !pinned) {
animator.SetBool("pinned", true);
pinned = true;
tambourineHitSound.Play();
} else {
// print("pinned, but not same position: " + this.gameObject.transform.position + " / " + collidedObject.transform.position);
}

View File

@@ -51,13 +51,16 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
void Update() {
Vector2 mousePos = m_camera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
RotateGun(mousePos, true);
// Vector2 mousePos = m_camera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
// RotateGun(mousePos, true);
if (grappleRope.isGrappling && !inDistanceRange && Vector2.Distance(grapplePoint, new Vector2(m_rigidBody2D.transform.position.x, m_rigidBody2D.transform.position.y)) < targetDistance) {
// print(Vector2.Distance(grapplePoint, new Vector2(m_rigidBody2D.transform.position.x, m_rigidBody2D.transform.position.y)) + ", target: " + targetDistance);
inDistanceRange = true;
}
if (grappleRope.isGrappling) {
RotateGun(grapplePoint, true);
}
if (inDistanceRange) {
m_distanceJoint2D.enabled = true;
}
@@ -76,6 +79,7 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
}
public void Grapple() {
grappleDistanceVector = grapplePoint - (Vector2)gunPivot.position;
// print("grapple");
m_springJoint2D.autoConfigureDistance = false;
m_distanceJoint2D.autoConfigureDistance = false;
@@ -89,6 +93,7 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
}
public void GrappleToTambourine(GameObject tambourine) {
grappleDistanceVector = grapplePoint - (Vector2)gunPivot.position;
grappleRope.enabled = true;
grapplePoint = tambourine.transform.position;
@@ -106,6 +111,7 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
}
public void GrappleToSurface(Vector2 surfacePoint) {
grappleDistanceVector = grapplePoint - (Vector2)gunPivot.position;
grappleRope.enabled = true;
grapplePoint = surfacePoint;
@@ -128,6 +134,7 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
m_distanceJoint2D.enabled = false;
inDistanceRange = false;
m_rigidBody2D.gravityScale = 1;
gunPivot.rotation = Quaternion.AngleAxis(70, Vector3.forward);
// print("disabled");
}

View File

@@ -25,6 +25,10 @@ public class Tutorial_GrapplingRope : MonoBehaviour {
[HideInInspector] public bool isGrappling = true;
bool straightLine = false;
[Header("Spider")]
bool hasPlayedThwip = false;
[SerializeField] GameObject sirJacques;
private void OnEnable() {
@@ -37,15 +41,19 @@ public class Tutorial_GrapplingRope : MonoBehaviour {
LinePointsToFirePoint();
m_lineRenderer.enabled = true;
sirJacques.SetActive(true);
}
private void OnDisable() {
// print("on disabled called");
m_lineRenderer.enabled = false;
isGrappling = false;
hasPlayedThwip = false;
sirJacques.SetActive(false);
}
private void LinePointsToFirePoint() {
sirJacques.transform.position = grapplingGun.firePoint.position;
for (int i = 0; i < precision; i++) {
m_lineRenderer.SetPosition(i, grapplingGun.firePoint.position);
}
@@ -53,6 +61,10 @@ public class Tutorial_GrapplingRope : MonoBehaviour {
void Update() {
moveTime += Time.deltaTime;
if (!hasPlayedThwip) {
this.gameObject.GetComponent<AudioSource>().Play();
hasPlayedThwip = true;
}
DrawRope();
}
@@ -60,10 +72,11 @@ public class Tutorial_GrapplingRope : MonoBehaviour {
// print("drawing");
// print("isGrappling: " + isGrappling);
if (!straightLine) {
float roundedLinePos = Mathf.Round(m_lineRenderer.GetPosition(precision - 1).x * 10.0f) * .01f;
float roundedGrapplePos = Mathf.Round(m_lineRenderer.GetPosition(precision - 1).x * 10.0f) * .01f;
// print(roundedLinePos + " / " + roundedGrapplePos);
if (roundedLinePos == roundedGrapplePos) {
// float roundedLinePos = Mathf.Round(m_lineRenderer.GetPosition(precision - 1).x * 100.0f) * .01f;
// float roundedGrapplePos = Mathf.Round(m_lineRenderer.GetPosition(precision - 1).x * 100.0f) * .01f;
// // print(roundedLinePos + " / " + roundedGrapplePos);
// if (roundedLinePos == roundedGrapplePos) {
if (m_lineRenderer.GetPosition(precision - 1).x == grapplingGun.grapplePoint.x) {
straightLine = true;
} else {
DrawRopeWaves();
@@ -87,18 +100,20 @@ public class Tutorial_GrapplingRope : MonoBehaviour {
}
void DrawRopeWaves() {
print(moveTime);
// print(moveTime);
for (int i = 0; i < precision; i++) {
float delta = (float)i / ((float)precision - 1f);
Vector2 offset = Vector2.Perpendicular(grapplingGun.grappleDistanceVector).normalized * ropeAnimationCurve.Evaluate(delta) * waveSize;
Vector2 targetPosition = Vector2.Lerp(grapplingGun.firePoint.position, grapplingGun.grapplePoint, delta) + offset;
Vector2 currentPosition = Vector2.Lerp(grapplingGun.firePoint.position, targetPosition, ropeProgressionCurve.Evaluate(moveTime) * ropeProgressionSpeed);
sirJacques.transform.position = currentPosition;
m_lineRenderer.SetPosition(i, currentPosition);
}
}
void DrawRopeNoWaves() {
sirJacques.transform.position = grapplingGun.grapplePoint;
m_lineRenderer.SetPosition(0, grapplingGun.firePoint.position);
m_lineRenderer.SetPosition(1, grapplingGun.grapplePoint);
}