added animation and camera

camera movement is very basic, animation is just right facing lol. also i know the organization is a bit of a mess, i promise i'll fix it
This commit is contained in:
slevy14
2023-04-19 21:34:00 -07:00
parent 686bc2528b
commit 32a1412a57
18 changed files with 15862 additions and 73 deletions

View File

@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour {
GameObject player;
[Header("Movement Shifting")]
[SerializeField] float xOffset;
[SerializeField] float yOffset;
[SerializeField] float smoothing;
[Header("Locking")]
[SerializeField] bool xLocked;
[SerializeField] bool yLocked;
void Awake() {
FindPlayer();
}
// Update is called once per frame
void Update()
{
if (player != null) {
float xPos = transform.position.x;
float yPos = transform.position.y;
if (!xLocked) {
xPos = Mathf.Lerp(transform.position.x, player.transform.position.x + xOffset, Time.deltaTime * smoothing);
}
if (!yLocked) {
yPos = Mathf.Lerp(transform.position.y, player.transform.position.y + yOffset, Time.deltaTime * smoothing);
}
this.gameObject.transform.position = new Vector3 (xPos, yPos, transform.position.z);
}
}
public void FindPlayer() {
player = GameObject.FindGameObjectWithTag("Player");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b97e4b0c854344a5688f47e90e5ae90a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -26,11 +26,14 @@ public class PlayerBehavior : MonoBehaviour
[SerializeField] private PlayerMovement playerController;
[SerializeField] private StateController stateController;
Animator animator;
void Start()
{
_rb = GetComponent<Rigidbody2D>();
stateController = GameObject.Find("StateController").GetComponent<StateController>();
animator = GetComponent<Animator>();
}
void Update()
@@ -55,6 +58,19 @@ public class PlayerBehavior : MonoBehaviour
{
LetGoOfGrapple();
}
Animate();
}
void Animate() {
// start walking
if (playerInput.actions["Move"].WasPressedThisFrame()) {
animator.SetBool("Walking", true);
}
// return to idle animation
if (playerInput.actions["Move"].WasReleasedThisFrame()) {
animator.SetBool("Walking", false);
}
}
void OnMove(InputValue value)

View File

@@ -15,6 +15,7 @@ public class StateController : MonoBehaviour {
public void RespawnPlayer() {
SetDeathCanvasActive(false);
GameObject.Find("Main Camera").GetComponent<CameraMovement>().FindPlayer();
Instantiate(player, spawnPoint.transform.position, spawnPoint.transform.rotation);
}