mirror of
https://github.com/frizbee19/FebGameJam.git
synced 2026-10-11 18:19:11 +00:00
did a minor tweak
This commit is contained in:
1 parent
8f2a693284
commit
11a2af2f5f
302 files changed
+1022
-167
No files matched your search
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MeanBird : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
// public Movement controller;
|
||||
public Animator animator;
|
||||
[SerializeField] float runSpeed = 5.0f;
|
||||
// private Rigidbody2D m_Rigidbody2D;
|
||||
private bool attack;
|
||||
private Vector3 direction;
|
||||
Transform player;
|
||||
[SerializeField] float detectRange;
|
||||
|
||||
private float accelTime = 1f;
|
||||
private float elapsed = 0f;
|
||||
private float t;
|
||||
|
||||
//constructs an NPC using parameters
|
||||
|
||||
void Start()
|
||||
{
|
||||
player = GameObject.FindGameObjectWithTag("Player").transform;
|
||||
animator.SetInteger("Animation", 2);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// if(Movement.pause) {
|
||||
// animator.SetFloat("Horizontal", 0);
|
||||
// }
|
||||
// if (animator != null && !Movement.pause) {
|
||||
// animator.SetFloat("Horizontal", (horizontalMove/Mathf.Abs(horizontalMove)));
|
||||
// animator.SetBool("Airborne", !controller.m_Grounded);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate() {
|
||||
if(!attack) {
|
||||
direction = player.position - transform.position;
|
||||
if(direction.magnitude < detectRange) {
|
||||
attack = true;
|
||||
animator.SetInteger("Animation", 3);
|
||||
Debug.Log("attack");
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(t < 1f) {
|
||||
t = elapsed / accelTime;
|
||||
t = t * t * (3f - 2f * t);
|
||||
}
|
||||
else {
|
||||
t = 1f;
|
||||
}
|
||||
GetComponent<Rigidbody2D>().MovePosition(transform.position + direction.normalized * runSpeed * t / 100f);
|
||||
elapsed += Time.fixedDeltaTime;
|
||||
}
|
||||
}
|
||||
private void OnTriggerEnter2D(Collider2D collision) {
|
||||
if (collision.tag == "Player") {
|
||||
collision.GetComponent<Health>().takeHit();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user