From 22bb25e95eecca4762101d42cbcd05ef7ce972ce Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sun, 20 Oct 2024 00:11:58 -0700 Subject: [PATCH] Added sword that always points at the mouse cursor help me i hate quaternions and trig so much --- Assets/Sword.cs | 23 +++++++++++++++++++++++ README.md | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Assets/Sword.cs diff --git a/Assets/Sword.cs b/Assets/Sword.cs new file mode 100644 index 0000000..daab4be --- /dev/null +++ b/Assets/Sword.cs @@ -0,0 +1,23 @@ +using UnityEngine; + +public class Sword : MonoBehaviour +{ + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start() + { + + } + + // Update is called once per frame + void Update() + { + transform.rotation = Quaternion.Euler( + new Vector3 (0, 0, Mathf.Atan2( + Screen.height/2 - Input.mousePosition.y, + Screen.width/2 - Input.mousePosition.x + ) * Mathf.Rad2Deg + 135) + ); + } + void Swing() { + } +} diff --git a/README.md b/README.md index 4d1fced..a10f819 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ - [x] Health - [x] Enemy takes health when touches - [ ] Enemy health bar -- [ ] Sword that points to mouse cursor +- [x] Sword that points to mouse cursor - [ ] Sword swings when click - [ ] Sword damages enemies in swing area - [ ] Wave spawns enemies