hopefully this doesnt break stuff

This commit is contained in:
Rizvee
2022-02-25 07:42:07 -06:00
parent 2195ac327b
commit 8191d4e79e
14 changed files with 537 additions and 46 deletions
+54
View File
@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bird : MonoBehaviour
{
// Start is called before the first frame update
public Movement controller;
public Animator animator;
public float horizontalMove = -1f;
[SerializeField] float runSpeed = 40f;
private Rigidbody2D m_Rigidbody2D;
[SerializeField] float deltaY;
[SerializeField] float frequency;
private float elapsed = 0;
[Range(0, .3f)][SerializeField] private float m_MovementSmoothing = .05f;
Vector3 m_Velocity = Vector3.zero;
//constructs an NPC using parameters
void Start()
{
m_Rigidbody2D = GetComponent<Rigidbody2D>();
horizontalMove *= runSpeed;
}
// 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);
// }
if(!Movement.pause){
elapsed += Time.deltaTime;
Vector3 targetVelocity = new Vector2(horizontalMove, Mathf.Sin(elapsed * frequency) * deltaY);
// And then smoothing it out and applying it to the character
m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);
}
else {
m_Rigidbody2D.velocity = Vector3.zero;
}
}
//NPC movement determined by script in subclasses
// void FixedUpdate()
// {
// controller.Move(horizontalMove *Time.fixedDeltaTime, false, false);
// }
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 61010a6ec25feb5498e828c19148706e
guid: 33ae55f3d792d2043a282a498c7203e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
-20
View File
@@ -1,20 +0,0 @@
//WIP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,11 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!62 &6200000
PhysicsMaterial2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Friction
friction: 1
bounciness: 0
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 52e104d77b96cbf4680cc9d0faad8d73
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 6200000
userData:
assetBundleName:
assetBundleVariant:
-20
View File
@@ -1,20 +0,0 @@
//WIP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Friend : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
+63
View File
@@ -0,0 +1,63 @@
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;
}
// 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;
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;
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 527e6d43896d2c4409cbb78ce4afdd04
guid: e2ac1ab11e649f44588372b17008679c
MonoImporter:
externalObjects: {}
serializedVersion: 2
+4
View File
@@ -44,6 +44,10 @@ public class PlayerMovement : MonoBehaviour
if (other.gameObject.tag == "Platform") {
transform.parent = other.transform;
}
// if(other.gameObject.tag == "Detection") {
// Debug.Log("detect");
// other.gameObject.GetComponent<MeanBird>().Detected(transform.position - other.gameObject.transform.position);
// }
}
void OnCollisionExit2D (Collision2D other) {
if (other.gameObject.tag == "Platform") {