diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs new file mode 100644 index 0000000000000000000000000000000000000000..9cfe71a8cc53a219aa5dc230a91f00a9428a0ddc --- /dev/null +++ b/MrBigsock/Assets/Code/Character.cs @@ -0,0 +1,48 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + +namespace BigSock { + // Common class for all characters. + public class Character : Entity { + + /* + Attack speed of the character. + */ + public double AttackSpeed => baseAttackSpeed; + public double baseAttackSpeed = 1; + + /* + Movement speed of the character. + */ + public double MovementSpeed => baseMovementSpeed; + public double baseMovementSpeed = 1; + + + /* + Damage of the character. + */ + public double Damage => baseDamage; + public double baseDamage = 1; + + + /* + Hit points of the character. + */ + public double HP { + get => baseHP; + set => baseHP = value; + } + public double baseHP = 10; + + + /* + Maximum hit points of the character. + */ + public double MaxHP => baseMaxHP; + public double baseMaxHP = 10; + + } +} diff --git a/MrBigsock/Assets/Code/orc/enemyMovement.cs.meta b/MrBigsock/Assets/Code/Character.cs.meta similarity index 83% rename from MrBigsock/Assets/Code/orc/enemyMovement.cs.meta rename to MrBigsock/Assets/Code/Character.cs.meta index 1968a501614ef3be5343f926747bfc5558ff7717..cf1f58c6fc28abb0faac4500c520575c1f365108 100644 --- a/MrBigsock/Assets/Code/orc/enemyMovement.cs.meta +++ b/MrBigsock/Assets/Code/Character.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 227b56e9abdf92742969115a025426b5 +guid: b60f5b1f7377c684ead118a2cc35234d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/MrBigsock/Assets/Code/DestroyObject.cs b/MrBigsock/Assets/Code/DestroyObject.cs index 48c7ad24cef9cd940a070cd0242ddf9327c53770..3b65125f8e0e81ce1006872a230c004057902e17 100644 --- a/MrBigsock/Assets/Code/DestroyObject.cs +++ b/MrBigsock/Assets/Code/DestroyObject.cs @@ -2,22 +2,26 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class DestroyObject : MonoBehaviour -{ - private void OnCollisionEnter2D(Collision2D collision) - { - Destroy(this.gameObject); - } +namespace BigSock { - // Start is called before the first frame update - void Start() - { - - } + public class DestroyObject : MonoBehaviour + { - // Update is called once per frame - void Update() - { - } + private void OnCollisionEnter2D(Collision2D collision) + { + Destroy(this.gameObject); + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + } + } } diff --git a/MrBigsock/Assets/Code/EmptyCollider.cs b/MrBigsock/Assets/Code/EmptyCollider.cs index b652a39227c30a48c0d708b4ed3007026c1598b9..c30a174629353474d63972b598b4cfe8210d7981 100644 --- a/MrBigsock/Assets/Code/EmptyCollider.cs +++ b/MrBigsock/Assets/Code/EmptyCollider.cs @@ -3,26 +3,28 @@ using System.Collections.Generic; using UnityEngine; using System; -public class EmptyCollider : MonoBehaviour -{ - public event Action<Collider2D> OnColliderEnter2D_Action; - public event Action<Collider2D> OnColliderStay2D_Action; - public event Action<Collider2D> OnColliderExit2D_Action; - - private void OnTriggerEnter2D(Collider2D other) - { - Debug.Log("enter"); - OnColliderEnter2D_Action?.Invoke(other); - } +namespace BigSock { + public class EmptyCollider : MonoBehaviour + { + public event Action<Collider2D> OnColliderEnter2D_Action; + public event Action<Collider2D> OnColliderStay2D_Action; + public event Action<Collider2D> OnColliderExit2D_Action; + + private void OnTriggerEnter2D(Collider2D other) + { + Debug.Log("enter"); + OnColliderEnter2D_Action?.Invoke(other); + } - private void OnTriggerStay2D(Collider2D other) - { - OnColliderStay2D_Action?.Invoke(other); - } + private void OnTriggerStay2D(Collider2D other) + { + OnColliderStay2D_Action?.Invoke(other); + } - private void OnTriggerExit2D(Collider2D other) - { - Debug.Log("exit"); - OnColliderExit2D_Action?.Invoke(other); - } -} + private void OnTriggerExit2D(Collider2D other) + { + Debug.Log("exit"); + OnColliderExit2D_Action?.Invoke(other); + } + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/EmptyCollider.cs.meta b/MrBigsock/Assets/Code/EmptyCollider.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..cbd026a1ac12879928f5697876c3e38dcd0e550d --- /dev/null +++ b/MrBigsock/Assets/Code/EmptyCollider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b1aeda8fe8f5c1f4fa7a8f47e2864211 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Entity.cs b/MrBigsock/Assets/Code/Entity.cs new file mode 100644 index 0000000000000000000000000000000000000000..c7a4a9d12d5a9c774c840367fe472ff88a82987c --- /dev/null +++ b/MrBigsock/Assets/Code/Entity.cs @@ -0,0 +1,12 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + +namespace BigSock { + // Takes and handles input and movement for a player character + public class Entity : MonoBehaviour { + + } +} diff --git a/MrBigsock/Assets/Code/Entity.cs.meta b/MrBigsock/Assets/Code/Entity.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..184ba5a62b1522d5556688f7be924acb133e411f --- /dev/null +++ b/MrBigsock/Assets/Code/Entity.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 57ff668aaac9f3444ba1f1e9528716ea +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index ec0e42a469353a01f376b13b47d216cd25539660..11b0f6cd4c1db95979403211984310ac14fe7904 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -4,151 +4,153 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; -// Takes and handles input and movement for a player character -public class PlayerController : MonoBehaviour -{ - public float moveSpeed = 1f; - public float collisionOffset = 0.05f; - public ContactFilter2D movementFilter; - - public GameObject attack; - - Vector2 movementInput; - SpriteRenderer spriteRenderer; - Rigidbody2D rb; - Animator animator; - List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); - - bool canMove = true; - - - - public bool Alive { get; private set; } = true; - public double Hp { get; private set; } = 100; - public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now; - public TimeSpan IFrameDuration { get; private set; } = new TimeSpan(0, 0, 2); - - // Start is called before the first frame update - void Start() - { - rb = GetComponent<Rigidbody2D>(); - animator = GetComponent<Animator>(); - spriteRenderer = GetComponent<SpriteRenderer>(); - } - - - /* - Adds damage to the player if they don't have IFrames. - */ - public bool TakeDamage(double amount) { - print($"[PlayerController.TakeDamage()] start. | {Hp} - {amount}"); - // Check if player has IFrames - if(NextTimeCanTakeDamage > DateTime.Now) - return false; - // Start new IFrames - NextTimeCanTakeDamage = DateTime.Now + IFrameDuration; - - // Add damage - Hp -= amount; - - TryKill(); - - return true; - } - - /* - Try to kill the player. - */ - public bool TryKill() { - print($"[PlayerController.TryKill()] start. | {Hp}, {Alive}"); - if(Alive && Hp <= 0) { - Alive = false; - - LockMovement(); - - return true; - } - return false; - } - - private void FixedUpdate() { - if(canMove) { - // If movement input is not 0, try to move - if(movementInput != Vector2.zero){ - - bool success = TryMove(movementInput); - - if(!success) { - success = TryMove(new Vector2(movementInput.x, 0)); - } - - if(!success) { - success = TryMove(new Vector2(0, movementInput.y)); - } - - animator.SetBool("isMoving", success); - } else { - animator.SetBool("isMoving", false); - } - - // Set direction of sprite to movement direction - if(movementInput.x < 0) { - spriteRenderer.flipX = true; - } else if (movementInput.x > 0) { - spriteRenderer.flipX = false; - } - } - - - } - - private void Update() - { - if (Input.GetKeyDown(KeyCode.Space)) - { - if (movementInput.x < 0 ) - { - Instantiate(attack, new Vector3(transform.position.x - 1.0f, transform.position.y, transform.position.z), attack.transform.rotation); - } else if (movementInput.x >= 0) - { - Instantiate(attack, new Vector3(transform.position.x + 1.0f, transform.position.y, transform.position.z), attack.transform.rotation); - } - } - } - - private bool TryMove(Vector2 direction) { - if(direction != Vector2.zero) { - // Check for potential collisions - int count = rb.Cast( - direction, // X and Y values between -1 and 1 that represent the direction from the body to look for collisions - movementFilter, // The settings that determine where a collision can occur on such as layers to collide with - castCollisions, // List of collisions to store the found collisions into after the Cast is finished - moveSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to the movement plus an offset - - if(count == 0){ - rb.MovePosition(rb.position + direction * moveSpeed * Time.fixedDeltaTime); - return true; - } else { - return false; - } - } else { - // Can't move if there's no direction to move in - return false; - } - - } - - void OnMove(InputValue movementValue) { - movementInput = movementValue.Get<Vector2>(); - } - - - public void LockMovement() { - canMove = false; - } - - public void UnlockMovement() { - canMove = true; - } -} +namespace BigSock { + + // Takes and handles input and movement for a player character + public class PlayerController : Character + { + public float collisionOffset = 0.05f; + public ContactFilter2D movementFilter; + + public GameObject attack; + + Vector2 movementInput; + SpriteRenderer spriteRenderer; + Rigidbody2D rb; + Animator animator; + List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); + + bool canMove = true; + + + + public bool Alive { get; private set; } = true; + //public double Hp { get; private set; } = 100; + public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now; + public TimeSpan IFrameDuration { get; private set; } = new TimeSpan(0, 0, 2); + + // Start is called before the first frame update + void Start() + { + rb = GetComponent<Rigidbody2D>(); + animator = GetComponent<Animator>(); + spriteRenderer = GetComponent<SpriteRenderer>(); + } + + + /* + Adds damage to the player if they don't have IFrames. + */ + public bool TakeDamage(double amount) { + print($"[PlayerController.TakeDamage()] start. | {HP} - {amount}"); + // Check if player has IFrames + if(NextTimeCanTakeDamage > DateTime.Now) + return false; + // Start new IFrames + NextTimeCanTakeDamage = DateTime.Now + IFrameDuration; + + // Add damage + HP -= amount; + + TryKill(); + + return true; + } + + /* + Try to kill the player. + */ + public bool TryKill() { + print($"[PlayerController.TryKill()] start. | {HP}, {Alive}"); + if(Alive && HP <= 0) { + Alive = false; + + LockMovement(); + + return true; + } + return false; + } + + private void FixedUpdate() { + if(canMove) { + // If movement input is not 0, try to move + if(movementInput != Vector2.zero){ + + bool success = TryMove(movementInput); + + if(!success) { + success = TryMove(new Vector2(movementInput.x, 0)); + } + + if(!success) { + success = TryMove(new Vector2(0, movementInput.y)); + } + + animator.SetBool("isMoving", success); + } else { + animator.SetBool("isMoving", false); + } + + // Set direction of sprite to movement direction + if(movementInput.x < 0) { + spriteRenderer.flipX = true; + } else if (movementInput.x > 0) { + spriteRenderer.flipX = false; + } + } + + + } + + private void Update() + { + if (Input.GetKeyDown(KeyCode.Space)) + { + if (movementInput.x < 0 ) + { + Instantiate(attack, new Vector3(transform.position.x - 1.0f, transform.position.y, transform.position.z), attack.transform.rotation); + } else if (movementInput.x >= 0) + { + Instantiate(attack, new Vector3(transform.position.x + 1.0f, transform.position.y, transform.position.z), attack.transform.rotation); + } + } + } + + private bool TryMove(Vector2 direction) { + if(direction != Vector2.zero) { + // Check for potential collisions + int count = rb.Cast( + direction, // X and Y values between -1 and 1 that represent the direction from the body to look for collisions + movementFilter, // The settings that determine where a collision can occur on such as layers to collide with + castCollisions, // List of collisions to store the found collisions into after the Cast is finished + (float) MovementSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to the movement plus an offset + + if(count == 0){ + rb.MovePosition(rb.position + direction * (float) MovementSpeed * Time.fixedDeltaTime); + return true; + } else { + return false; + } + } else { + // Can't move if there's no direction to move in + return false; + } + + } + + void OnMove(InputValue movementValue) { + movementInput = movementValue.Get<Vector2>(); + } + + + public void LockMovement() { + canMove = false; + } + + public void UnlockMovement() { + canMove = true; + } + } +} diff --git a/MrBigsock/Assets/Code/attack/AttackMovement.cs b/MrBigsock/Assets/Code/attack/AttackMovement.cs index e9a92a99e1133d96d64d3b4fe77504ea922e1736..f6bf8f0f4cddd60dcde8a7d055216c5902633b46 100644 --- a/MrBigsock/Assets/Code/attack/AttackMovement.cs +++ b/MrBigsock/Assets/Code/attack/AttackMovement.cs @@ -4,52 +4,55 @@ using UnityEngine; using UnityEngine.InputSystem; using static UnityEngine.GraphicsBuffer; -public class AttackMovement : MonoBehaviour -{ - public float speed = 10.0f; - bool moved = false; - float horizontalInput; - float verticalInput; +namespace BigSock { + public class AttackMovement : MonoBehaviour + { + public float speed = 10.0f; + bool moved = false; + float horizontalInput; + float verticalInput; - // Start is called before the first frame update - void Start() - { - } - // Update is called once per frame - void Update() - { - if (!moved) - { - horizontalInput = Input.GetAxis("Horizontal"); - verticalInput = Input.GetAxis("Vertical"); - moved = true; - } - if (horizontalInput != 0 && verticalInput != 0) - { - transform.Translate(new Vector3(1 * horizontalInput, 1 * verticalInput, 0) * speed * Time.deltaTime); - } - else if (horizontalInput < 0) - { - transform.Translate(-Vector3.right * speed * Time.deltaTime); - } - else if (horizontalInput > 0) - { - transform.Translate(Vector3.right * speed * Time.deltaTime); - } - else if (verticalInput > 0) - { - transform.Translate(Vector3.up * speed * Time.deltaTime); - } - else if (verticalInput < 0) - { - transform.Translate(-Vector3.up * speed * Time.deltaTime); - } + // Start is called before the first frame update + void Start() + { + } - else - { - transform.Translate(Vector3.right * speed * Time.deltaTime); - } - } + // Update is called once per frame + void Update() + { + if (!moved) + { + horizontalInput = Input.GetAxis("Horizontal"); + verticalInput = Input.GetAxis("Vertical"); + moved = true; + } + if (horizontalInput != 0 && verticalInput != 0) + { + transform.Translate(new Vector3(1 * horizontalInput, 1 * verticalInput, 0) * speed * Time.deltaTime); + } + else if (horizontalInput < 0) + { + transform.Translate(-Vector3.right * speed * Time.deltaTime); + } + else if (horizontalInput > 0) + { + transform.Translate(Vector3.right * speed * Time.deltaTime); + } + else if (verticalInput > 0) + { + transform.Translate(Vector3.up * speed * Time.deltaTime); + } + else if (verticalInput < 0) + { + transform.Translate(-Vector3.up * speed * Time.deltaTime); + } + + else + { + transform.Translate(Vector3.right * speed * Time.deltaTime); + } + } + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/orc/EnemyController.cs b/MrBigsock/Assets/Code/orc/EnemyController.cs new file mode 100644 index 0000000000000000000000000000000000000000..375479393dfb552fbf14a9933898b9c7686eec4e --- /dev/null +++ b/MrBigsock/Assets/Code/orc/EnemyController.cs @@ -0,0 +1,167 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.Linq; + + +namespace BigSock { + + public partial class EnemyController : Character { + public float collisionOffset = 0.05f; + public ContactFilter2D movementFilter; + List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); + + private Transform target; + Animator m_Animator; + private float distance; + + private float canAttack; + + private EmptyCollider followCollider; + private EmptyCollider attackCollider; + + private bool isInMelee = false; + + + Rigidbody2D rb; + + // private Collider2D_Proxy secondCollider; + + void Start(){ + rb = GetComponent<Rigidbody2D>(); + + m_Animator = gameObject.GetComponent<Animator>(); + + followCollider = transform.Find("followCollider").GetComponent<EmptyCollider>(); + followCollider.OnColliderEnter2D_Action += Move_OnColliderEnter2D; + followCollider.OnColliderStay2D_Action += Move_OnColliderStay2D; + followCollider.OnColliderExit2D_Action += Move_OnColliderExit2D; + + attackCollider = transform.Find("MeleeCollider").GetComponent<EmptyCollider>(); + attackCollider.OnColliderEnter2D_Action += Attack_OnColliderEnter2D; + attackCollider.OnColliderStay2D_Action += Attack_OnColliderStay2D; + attackCollider.OnColliderExit2D_Action += Attack_OnColliderExit2D; + } + + private void RotateAnimation(Vector2 direction) + { + if (direction.x > 0.01f){ + gameObject.GetComponent<SpriteRenderer>().flipX = false; + } + else if (direction.x < -0.01f){ + gameObject.GetComponent<SpriteRenderer>().flipX = true; + } + + } + + private void Update(){ + if (target != null && !isInMelee){ + + /* //walk + float step = speed * Time.deltaTime; + transform.position = Vector2.MoveTowards(transform.position, target.position, step); + + //distance = Vector3.Distance (transform.position, target.position); + //roter + RotateAnimation(); + */ + + TryMove((new Vector2(target.position.x, target.position.y) - rb.position).normalized); + } + else{ + + } + } + + private bool TryMove(Vector2 direction) { + + if(direction != Vector2.zero) { + + // Check for potential collisions + int count = rb.Cast( + direction, // X and Y values between -1 and 1 that represent the direction from the body to look for collisions + movementFilter, // The settings that determine where a collision can occur on such as layers to collide with + castCollisions, // List of collisions to store the found collisions into after the Cast is finished + (float) MovementSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to the movement plus an offset + //Debug.Log($"cast {string.Join(", ", castCollisions.Select(x => $"{x.collider.isTrigger}"))}"); + //Debug.Log($"rb.position : {rb.position}"); + //Debug.Log($"target.position : {target.position}"); + //Debug.Log($"direction : {direction}"); + if(count == 0){ + rb.MovePosition(rb.position + direction * (float) MovementSpeed * Time.fixedDeltaTime); + print($"rb.position {rb.position}"); + print($"direction {direction}"); + RotateAnimation(direction); + + return true; + } else { + return false; + } + } else { + // Can't move if there's no direction to move in + return false; + } + + } + } + + + public partial class EnemyController { //attack + + private void Attack_OnColliderEnter2D(Collider2D other){ + if (other.gameObject.tag == "Player") + isInMelee = true; + } + + + + private void Attack_OnColliderStay2D(Collider2D other){ + if (other.gameObject.tag == "Player"){ + var player = other.gameObject.GetComponent<PlayerController>(); + if(player.TakeDamage(Damage)){ + //knockback ? + //animer nå ? + + } + } + } + private void Attack_OnColliderExit2D(Collider2D other){ + if (other.gameObject.tag == "Player") + isInMelee = false; + } + + } + + public partial class EnemyController { //move + + private void Move_OnColliderEnter2D(Collider2D other) + { + Debug.Log("enter"); + if (other.gameObject.tag == "Player"){ + Debug.Log("enter if"); + + m_Animator.SetTrigger("walk"); + target = other.transform; + } + } + + private void Move_OnColliderStay2D(Collider2D other) + { + + if (other.gameObject.tag == "Player"){ + + } + } + + private void Move_OnColliderExit2D(Collider2D other) + { + if (other.gameObject.tag == "Player"){ + m_Animator.SetTrigger("idle"); + target = other.transform; + target = null; + } + } + + } + +} diff --git a/MrBigsock/Assets/Code/orc/EnemyController.cs.meta b/MrBigsock/Assets/Code/orc/EnemyController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..7e08b3286144b1b6fc08b045cbcc491151acd096 --- /dev/null +++ b/MrBigsock/Assets/Code/orc/EnemyController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 17f5c644f1bb62e49add8056d54c83ff +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/orc/enemyMovement.cs b/MrBigsock/Assets/Code/orc/enemyMovement.cs deleted file mode 100644 index c8e2e89af821d14af2ccc9e086cdaa20e7cc580a..0000000000000000000000000000000000000000 --- a/MrBigsock/Assets/Code/orc/enemyMovement.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using System.Linq; - -public partial class enemyMovement : MonoBehaviour{ - public float speed = 0.6f; - - public float collisionOffset = 0.05f; - public ContactFilter2D movementFilter; - List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); - - private Transform target; - Animator m_Animator; - private float distance; - - public float attackSpeed = 1f; - private float canAttack; - private float baseDamage = 1f; - - private EmptyCollider followCollider; - private EmptyCollider attackCollider; - - private bool isInMelee = false; - - - Rigidbody2D rb; - - // private Collider2D_Proxy secondCollider; - - void Start(){ - rb = GetComponent<Rigidbody2D>(); - - m_Animator = gameObject.GetComponent<Animator>(); - - followCollider = transform.Find("followCollider").GetComponent<EmptyCollider>(); - followCollider.OnColliderEnter2D_Action += Move_OnColliderEnter2D; - followCollider.OnColliderStay2D_Action += Move_OnColliderStay2D; - followCollider.OnColliderExit2D_Action += Move_OnColliderExit2D; - - attackCollider = transform.Find("MeleeCollider").GetComponent<EmptyCollider>(); - attackCollider.OnColliderEnter2D_Action += Attack_OnColliderEnter2D; - attackCollider.OnColliderStay2D_Action += Attack_OnColliderStay2D; - attackCollider.OnColliderExit2D_Action += Attack_OnColliderExit2D; - } - - private void RotateAnimation(Vector2 direction) - { - if (direction.x > 0.01f){ - gameObject.GetComponent<SpriteRenderer>().flipX = false; - } - else if (direction.x < -0.01f){ - gameObject.GetComponent<SpriteRenderer>().flipX = true; - } - - } - - private void Update(){ - if (target != null && !isInMelee){ - - /* //walk - float step = speed * Time.deltaTime; - transform.position = Vector2.MoveTowards(transform.position, target.position, step); - - //distance = Vector3.Distance (transform.position, target.position); - //roter - RotateAnimation(); - */ - - TryMove((new Vector2(target.position.x, target.position.y) - rb.position).normalized); - } - else{ - - } - } - - private bool TryMove(Vector2 direction) { - - if(direction != Vector2.zero) { - - // Check for potential collisions - int count = rb.Cast( - direction, // X and Y values between -1 and 1 that represent the direction from the body to look for collisions - movementFilter, // The settings that determine where a collision can occur on such as layers to collide with - castCollisions, // List of collisions to store the found collisions into after the Cast is finished - speed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to the movement plus an offset - //Debug.Log($"cast {string.Join(", ", castCollisions.Select(x => $"{x.collider.isTrigger}"))}"); - //Debug.Log($"rb.position : {rb.position}"); - //Debug.Log($"target.position : {target.position}"); - //Debug.Log($"direction : {direction}"); - if(count == 0){ - rb.MovePosition(rb.position + direction * speed * Time.fixedDeltaTime); - print($"rb.position {rb.position}"); - print($"direction {direction}"); - RotateAnimation(direction); - - return true; - } else { - return false; - } - } else { - // Can't move if there's no direction to move in - return false; - } - - } -} - - - public partial class enemyMovement { //attack - - private void Attack_OnColliderEnter2D(Collider2D other){ - if (other.gameObject.tag == "Player") - isInMelee = true; - } - - - - private void Attack_OnColliderStay2D(Collider2D other){ - if (other.gameObject.tag == "Player"){ - var player = other.gameObject.GetComponent<PlayerController>(); - if(player.TakeDamage(baseDamage)){ - //knockback ? - //animer nå ? - - } - } - } - private void Attack_OnColliderExit2D(Collider2D other){ - if (other.gameObject.tag == "Player") - isInMelee = false; - } - - } - - public partial class enemyMovement { //move - - private void Move_OnColliderEnter2D(Collider2D other) - { - Debug.Log("enter"); - if (other.gameObject.tag == "Player"){ - Debug.Log("enter if"); - - m_Animator.SetTrigger("walk"); - target = other.transform; - } - } - - private void Move_OnColliderStay2D(Collider2D other) - { - - if (other.gameObject.tag == "Player"){ - - } - } - - private void Move_OnColliderExit2D(Collider2D other) - { - if (other.gameObject.tag == "Player"){ - m_Animator.SetTrigger("idle"); - target = other.transform; - target = null; - } - } - - } - - diff --git a/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab b/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab index 79bd4893f6c7c7af46705055a0e9d3aa9533b7f5..722949cfe5da455c916a1dc94e0257652cf069ac 100644 --- a/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab +++ b/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab @@ -140,14 +140,13 @@ MonoBehaviour: m_GameObject: {fileID: 2996495149472241661} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 227b56e9abdf92742969115a025426b5, type: 3} + m_Script: {fileID: 11500000, guid: 17f5c644f1bb62e49add8056d54c83ff, type: 3} m_Name: m_EditorClassIdentifier: - speed: 0.6 collisionOffset: 0.05 movementFilter: useTriggers: 0 - useLayerMask: 1 + useLayerMask: 0 useDepth: 0 useOutsideDepth: 0 useNormalAngle: 0 @@ -159,7 +158,6 @@ MonoBehaviour: maxDepth: 0 minNormalAngle: 0 maxNormalAngle: 0 - attackSpeed: 3 --- !u!61 &2395291586284291126 BoxCollider2D: m_ObjectHideFlags: 0 @@ -244,7 +242,7 @@ MonoBehaviour: m_GameObject: {fileID: 7539630614846898202} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 71e6597ff848be34e979f08b6041384a, type: 3} + m_Script: {fileID: 11500000, guid: b1aeda8fe8f5c1f4fa7a8f47e2864211, type: 3} m_Name: m_EditorClassIdentifier: --- !u!1 &8620845285361089561 @@ -305,6 +303,6 @@ MonoBehaviour: m_GameObject: {fileID: 8620845285361089561} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 71e6597ff848be34e979f08b6041384a, type: 3} + m_Script: {fileID: 11500000, guid: b1aeda8fe8f5c1f4fa7a8f47e2864211, type: 3} m_Name: m_EditorClassIdentifier: