Interaction

This commit is contained in:
janis
2022-02-14 17:12:18 +01:00
parent 352581713f
commit cd3d015226
336 changed files with 59574 additions and 332 deletions

View File

@@ -2,25 +2,37 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Handles the player's movement, such as running, walking, sneaking
public class PlayerMovement : MonoBehaviour
{
{
// Speed multiplier of the movement
[SerializeField] float moveSpeed = 5f;
[SerializeField] Rigidbody2D rb;
[SerializeField] Animator animator;
Rigidbody2D rb;
Animator animator;
Vector2 movement;
private void Update()
void Start()
{
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
// Normalize, so the player is not faster by moving diagonally
movement.Normalize();
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
private void FixedUpdate()
void FixedUpdate()
{
if (rb != null)
{