From fccce023dd5cc5dcbac46ef4d10cb24155babb1d Mon Sep 17 00:00:00 2001 From: Toly65 <88860967+Toly65@users.noreply.github.com> Date: Thu, 12 Aug 2021 23:56:01 +0100 Subject: [PATCH] Add files via upload --- Scripts/BuffManager.cs | 109 ++++++ Scripts/BuffManager.cs.meta | 11 + Scripts/Bullet.cs | 181 +++++++++ Scripts/Bullet.cs.meta | 11 + Scripts/Display.cs | 24 ++ Scripts/Display.cs.meta | 11 + Scripts/Explosive.cs | 173 +++++++++ Scripts/Explosive.cs.meta | 11 + Scripts/GripScript.cs | 24 ++ Scripts/GripScript.cs.meta | 11 + Scripts/Gun.cs | 366 ++++++++++++++++++ Scripts/Gun.cs.meta | 11 + Scripts/HealthManager.cs | 103 +++++ Scripts/HealthManager.cs.meta | 11 + Scripts/LitterallyNothing.asset | 29 ++ Scripts/LitterallyNothing.asset.meta | 8 + Scripts/Lookat.cs | 58 +++ Scripts/Lookat.cs.meta | 11 + Scripts/PlayerHealthManager.cs | 175 +++++++++ Scripts/PlayerHealthManager.cs.meta | 11 + Scripts/ScopeManager.cs | 25 ++ Scripts/ScopeManager.cs.meta | 11 + Scripts/Spark.cs | 15 + Scripts/Spark.cs.meta | 11 + Scripts/StatManager.cs | 21 + Scripts/StatManager.cs.meta | 11 + Scripts/improvedHitbox.meta | 8 + Scripts/improvedHitbox/DamageDetector.cs | 18 + Scripts/improvedHitbox/DamageDetector.cs.meta | 11 + .../improvedHitbox/ImprovedHitBoxAssigner.cs | 51 +++ .../ImprovedHitBoxAssigner.cs.meta | 11 + .../improvedHitbox/ImprovedHitBoxManager.cs | 88 +++++ .../ImprovedHitBoxManager.cs.meta | 11 + Scripts/improvedHitbox/improvedHitbox.cs | 54 +++ Scripts/improvedHitbox/improvedHitbox.cs.meta | 11 + 35 files changed, 1706 insertions(+) create mode 100644 Scripts/BuffManager.cs create mode 100644 Scripts/BuffManager.cs.meta create mode 100644 Scripts/Bullet.cs create mode 100644 Scripts/Bullet.cs.meta create mode 100644 Scripts/Display.cs create mode 100644 Scripts/Display.cs.meta create mode 100644 Scripts/Explosive.cs create mode 100644 Scripts/Explosive.cs.meta create mode 100644 Scripts/GripScript.cs create mode 100644 Scripts/GripScript.cs.meta create mode 100644 Scripts/Gun.cs create mode 100644 Scripts/Gun.cs.meta create mode 100644 Scripts/HealthManager.cs create mode 100644 Scripts/HealthManager.cs.meta create mode 100644 Scripts/LitterallyNothing.asset create mode 100644 Scripts/LitterallyNothing.asset.meta create mode 100644 Scripts/Lookat.cs create mode 100644 Scripts/Lookat.cs.meta create mode 100644 Scripts/PlayerHealthManager.cs create mode 100644 Scripts/PlayerHealthManager.cs.meta create mode 100644 Scripts/ScopeManager.cs create mode 100644 Scripts/ScopeManager.cs.meta create mode 100644 Scripts/Spark.cs create mode 100644 Scripts/Spark.cs.meta create mode 100644 Scripts/StatManager.cs create mode 100644 Scripts/StatManager.cs.meta create mode 100644 Scripts/improvedHitbox.meta create mode 100644 Scripts/improvedHitbox/DamageDetector.cs create mode 100644 Scripts/improvedHitbox/DamageDetector.cs.meta create mode 100644 Scripts/improvedHitbox/ImprovedHitBoxAssigner.cs create mode 100644 Scripts/improvedHitbox/ImprovedHitBoxAssigner.cs.meta create mode 100644 Scripts/improvedHitbox/ImprovedHitBoxManager.cs create mode 100644 Scripts/improvedHitbox/ImprovedHitBoxManager.cs.meta create mode 100644 Scripts/improvedHitbox/improvedHitbox.cs create mode 100644 Scripts/improvedHitbox/improvedHitbox.cs.meta diff --git a/Scripts/BuffManager.cs b/Scripts/BuffManager.cs new file mode 100644 index 0000000..63b5061 --- /dev/null +++ b/Scripts/BuffManager.cs @@ -0,0 +1,109 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +[AddComponentMenu("")] +public class BuffManager : UdonSharpBehaviour +{ + public UdonBehaviour HealthManager; + public bool isBleeding; + public bool isPoisoned; + public float BleedDamage = 5f; + public float PoisonDamage = 5f; + public int BleedTime = 5; + public int PoisonTime = 10; + + private float currentTime_Bleed; + private float currentTime_Poison; + private float wantedTime_Bleed; + private float wantedTime_Poison; + private float waitTime = 1f; + private bool bleedIsFirstActive = true; + private bool poisonIsFirstActive = true; + private int currentBleedTime = 0; + private int currentPoisonTime = 0; + private int defaultBleedTime; + private int defaultPoisonTime; + private float defaultBleedDamage; + private float defaultPoisonDamage; + + private void Start() + { + defaultBleedTime = BleedTime; + defaultPoisonTime = PoisonTime; + defaultBleedDamage = BleedDamage; + defaultPoisonDamage = PoisonDamage; + } + + private void Update() + { + Debug.Log(currentTime_Bleed); + if (isBleeding) + { + if (bleedIsFirstActive) + { + currentTime_Bleed = Time.time; + wantedTime_Bleed = Time.time + waitTime; + bleedIsFirstActive = false; + } + + currentTime_Bleed += Time.deltaTime; + + if (currentTime_Bleed >= wantedTime_Bleed) + { + HealthManager.SetProgramVariable("Modifier", BleedDamage*-1); + HealthManager.SendCustomEvent("ModifyHealth"); + bleedIsFirstActive = true; + currentBleedTime++; + } + } + + if (isPoisoned) + { + if (poisonIsFirstActive) + { + currentTime_Poison = Time.time; + poisonIsFirstActive = false; + wantedTime_Poison = Time.time + waitTime; + } + else + { + currentTime_Poison += Time.deltaTime; + } + + if (currentTime_Poison > wantedTime_Poison) + { + HealthManager.SetProgramVariable("Modifier", PoisonDamage*-1); + poisonIsFirstActive = true; + currentPoisonTime++; + } + } + + if (currentBleedTime > BleedTime) + { + ResetBleeding(); + } + if (currentPoisonTime > PoisonTime) + { + ResetPoison(); + } + } + + public void ResetBleeding() + { + isBleeding = false; + currentBleedTime = 0; + BleedTime = defaultBleedTime; + BleedDamage = defaultBleedDamage; + } + + public void ResetPoison() + { + isPoisoned = false; + currentPoisonTime = 0; + PoisonTime = defaultPoisonTime; + PoisonDamage = defaultPoisonDamage; + } +} diff --git a/Scripts/BuffManager.cs.meta b/Scripts/BuffManager.cs.meta new file mode 100644 index 0000000..8716600 --- /dev/null +++ b/Scripts/BuffManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6fa5cb5111bfa7143b0b7a27f59a90d5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Bullet.cs b/Scripts/Bullet.cs new file mode 100644 index 0000000..664cf3a --- /dev/null +++ b/Scripts/Bullet.cs @@ -0,0 +1,181 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +[AddComponentMenu("")] +public class Bullet : UdonSharpBehaviour +{ + //public configuarble variables + public bool sendTriggerMessage = false; + private ContactPoint contact; + public GameObject BulletSpark; + //public Explosive explodeScript; + private UdonBehaviour Target; + public float StartDamage = 25f; + public float MinDamage = 10f; + private float totalDamage; + public float lifetime = 15.0f; + public int BleedTimeToAdd = 1; + public float BleedDamageToAdd = 5f; + public bool Rocket; + public float rocketPropulsion; + public float PropulsionTime; + public float RotationSpeed; + public GameObject SpawningGun; + + //private calculation variables + private float currentVel; + private float vpercent; + [HideInInspector] public float MaxVelocity; + private Rigidbody rb; + private float currentTime; + private float wantedTime; + private bool isFirst = true; + + //pivate collison raycasting detection variables + private LayerMask layerMask = 10; //make sure we aren't in this layer + private float skinWidth = 0.1f; //probably doesn't need to be changed + private float minimumExtent; + private float partialExtent; + private float sqrMinimumExtent; + private Vector3 previousPosition; + private Rigidbody myRigidbody; + private Collider myCollider; + + private void Start() + { + Destroy(gameObject, lifetime); + rb = (Rigidbody)gameObject.GetComponent(typeof(Rigidbody)); + currentTime = Time.time; + wantedTime = currentTime + 0.01f; + + + myRigidbody = GetComponent(); + myCollider = GetComponent(); + previousPosition = myRigidbody.position; + minimumExtent = Mathf.Min(Mathf.Min(myCollider.bounds.extents.x, myCollider.bounds.extents.y), myCollider.bounds.extents.z); + partialExtent = minimumExtent * (1.0f - skinWidth); + sqrMinimumExtent = minimumExtent * minimumExtent; + } + + private void Update() + { + currentTime += Time.deltaTime; + + if (currentTime >= wantedTime && isFirst) + { + MaxVelocity = rb.velocity.magnitude; + isFirst = false; + } + if (!(currentTime >= wantedTime) || isFirst) return; + currentVel = rb.velocity.magnitude; + vpercent = (currentVel / MaxVelocity); + totalDamage = StartDamage * vpercent; + + if (totalDamage < MinDamage) + { + totalDamage = MinDamage; + } + + + } + + void FixedUpdate() + { + //have we moved more than our minimum extent? + Vector3 movementThisStep = myRigidbody.position - previousPosition; + float movementSqrMagnitude = movementThisStep.sqrMagnitude; + + if (movementSqrMagnitude > sqrMinimumExtent) + { + float movementMagnitude = Mathf.Sqrt(movementSqrMagnitude); + RaycastHit hitInfo; + + //check for obstructions we might have missed + if (Physics.Raycast(previousPosition, movementThisStep, out hitInfo, movementMagnitude, layerMask.value)) + { + if (!hitInfo.collider) + return; + + if (hitInfo.collider.isTrigger) + BulletStuff(hitInfo.collider.gameObject); + // BulletStuff(PlayerRoot); + + if (!hitInfo.collider.isTrigger) + myRigidbody.position = hitInfo.point - (movementThisStep / movementMagnitude) * partialExtent; + } + } + + previousPosition = myRigidbody.position; + } + + private void OnCollisionEnter(Collision other) + { + var otherObject = other.gameObject; + BulletStuff(otherObject); + contact = other.GetContact(0); + Debug.Log("collisionEntered"); + + var hit = VRCInstantiate(BulletSpark); + hit.transform.position = transform.position; + hit.transform.position = contact.point; + hit.SetActive(true); + + + Destroy(gameObject); + } + + private void OnTriggerEnter(Collider other) + { + Debug.Log("triggerEntered"); + var otherObject = other.gameObject; + BulletStuff(otherObject); + } + private void BulletStuff(GameObject otherObject) + { + //var point = other.ClosestPoint(); + Debug.Log("oh look, a hit"); + //var hit = VRCInstantiate(BulletSpark); + //hit.transform.position = contact.point; + + + + if ((UdonBehaviour)otherObject.GetComponent(typeof(UdonBehaviour)) == null) + { + //TrueParent.gameObject.SetActive(false); + Debug.Log("Trigger"); + Debug.Log("collided with: " + otherObject.name); + } + else + { + if(Networking.GetOwner(gameObject)==Networking.GetOwner(SpawningGun)) + { + Target = (UdonBehaviour)otherObject.GetComponent(typeof(UdonBehaviour)); + Debug.Log("udon collision with " + Target.name); + Target.SetProgramVariable("Modifier", (totalDamage * -1)); + Target.SendCustomEvent("ModifyHealth"); + } + + + /* + BuffManagerTarget.SetProgramVariable("isBleeding", true); + int BleedTime = (int)BuffManagerTarget.GetProgramVariable("BleedTime"); + BleedTime += BleedTimeToAdd; + BuffManagerTarget.SetProgramVariable("BleedTime", BleedTime); + + float BleedDamage = (float)BuffManagerTarget.GetProgramVariable("BleedDamage"); + BleedDamage += BleedDamageToAdd; + BuffManagerTarget.SetProgramVariable("BleedDamage", BleedDamage); + + Debug.Log("Bullet did: " + totalDamage);*/ + + + } + + Destroy(gameObject); + + } + +} diff --git a/Scripts/Bullet.cs.meta b/Scripts/Bullet.cs.meta new file mode 100644 index 0000000..902c2cd --- /dev/null +++ b/Scripts/Bullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 75939d62e3396ad44818ac1878d3ad84 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Display.cs b/Scripts/Display.cs new file mode 100644 index 0000000..29f79ba --- /dev/null +++ b/Scripts/Display.cs @@ -0,0 +1,24 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +[AddComponentMenu("")] +public class Display : UdonSharpBehaviour +{ + private VRCPlayerApi localPlayer; + public GameObject leftHandPosition; + public GameObject rightHandPosition; + + private void Start() + { + localPlayer = Networking.LocalPlayer; + } + + void Update() + { + leftHandPosition.transform.SetPositionAndRotation(localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.LeftHand).position, localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.LeftHand).rotation); + rightHandPosition.transform.SetPositionAndRotation(localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).position, localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).rotation); + } +} diff --git a/Scripts/Display.cs.meta b/Scripts/Display.cs.meta new file mode 100644 index 0000000..09dae2f --- /dev/null +++ b/Scripts/Display.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0019430d80c3a2140b0018f2cf7e1c20 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Explosive.cs b/Scripts/Explosive.cs new file mode 100644 index 0000000..2808a2c --- /dev/null +++ b/Scripts/Explosive.cs @@ -0,0 +1,173 @@ + +using UdonSharp; +using UnityEngine; +using UnityEngine.SocialPlatforms; +using VRC.SDKBase; +using VRC.Udon; + +[AddComponentMenu("")] +public class Explosive : UdonSharpBehaviour +{ + public float ExplosivePower = 750f; + public float ExplosiveRange = 5f; + public float UpwardsModifier = 3f; + public float playerLaunchModifier = 0.01f; + public float Damage = 50.0f; + public float MaxSpeedFromExplosionForPlayer = 80.0f; + public GameObject ExplosiveViz; + public AudioSource Audio; + public AudioClip[] clips = new AudioClip[4]; + private AudioClip ExplosionAudio; + + private float distanceFromPlayer; + + public GameObject GunRoot; + + private VRCPlayerApi localPlayer; + private VRCPlayerApi TrueOwner; + private void Start() + { + localPlayer = Networking.LocalPlayer; + TrueOwner = Networking.GetOwner(GunRoot); + + + Explode(); + } + + private void Update() + { + + } + + + public void Explode() + { + + distanceFromPlayer = Vector3.Distance(transform.position, localPlayer.GetPosition()); + + + + if (distanceFromPlayer <= 50) + { + ExplosionAudio = clips[1]; + } + else if (distanceFromPlayer <= 250) + { + ExplosionAudio = clips[2]; + } + else + { + ExplosionAudio = clips[3]; + } + + if (ExplosiveRange <= 2) + { + ExplosionAudio = clips[0]; + } + localPlayer = Networking.LocalPlayer; + + Audio.PlayOneShot(ExplosionAudio); + + var Explosion = VRCInstantiate(ExplosiveViz); + Explosion.SetActive(true); + Explosion.transform.position = transform.position; + Explosion.transform.localScale = new Vector3(ExplosiveRange, ExplosiveRange, ExplosiveRange); + + + var colliders = Physics.OverlapSphere(transform.position, ExplosiveRange); + + foreach (var hitCol in colliders) + { + if(hitCol != null) + { + Debug.Log(hitCol.gameObject.name); + if (hitCol.gameObject.name.Contains("hitbox") || hitCol.gameObject.name.Contains("[Object]") ) + { + + bool isVisible = false; + + RaycastHit hit; + if (Physics.Raycast(transform.position, (hitCol.transform.position - transform.position), out hit)) + { + if (hit.collider.gameObject.name.Contains("hitbox") || hit.collider.gameObject.name.Contains("[Object]")) + { + isVisible = true; + } + } + + //case of random rigidbodies + if(hit.collider.gameObject.name.Contains("[Object]") && localPlayer == TrueOwner) + { + //This IF statement breaks when there are no rigidbodies, because unity said fuck you + if (isVisible && (Rigidbody)hitCol.GetComponent(typeof(Rigidbody)) != null) + { + + //set ownership of everything that gets moved + Networking.SetOwner(TrueOwner, hitCol.gameObject); + var rb = (Rigidbody)hitCol.GetComponent(typeof(Rigidbody)); + rb.AddExplosionForce(ExplosivePower, Explosion.transform.position, ExplosiveRange, UpwardsModifier); + + //keeping this in incase you want random objects to take damage + if ((UdonBehaviour)hitCol.GetComponent(typeof(UdonBehaviour)) != null) + { + var TargetHealthManager = (UdonBehaviour)hitCol.GetComponent(typeof(UdonBehaviour)); + + var Distance = Vector3.Distance(hitCol.transform.position, transform.position); + var totalDamage = Damage / Distance; + if (totalDamage > Damage) + { + totalDamage = Damage; + } + + if (TargetHealthManager.GetProgramVariable("Modifier") != null) + { + TargetHealthManager.SetProgramVariable("Modifier", (totalDamage * -1)); + TargetHealthManager.SendCustomEvent("ModifyHealth"); + } + } + } + } + + + //todo, case of torso and case of legs + + //the torso handles damage + if(isVisible && hitCol.gameObject.name.Contains("torso") && localPlayer == TrueOwner) + { + if ((UdonBehaviour)hitCol.GetComponent(typeof(UdonBehaviour)) != null&&localPlayer == Networking.GetOwner(GunRoot)) + { + var TargetHealthManager = (UdonBehaviour)hitCol.GetComponent(typeof(UdonBehaviour)); + + var Distance = Vector3.Distance(hitCol.transform.position, transform.position); + var totalDamage = Damage / Distance; + if (totalDamage > Damage) + { + totalDamage = Damage; + } + + if (TargetHealthManager.GetProgramVariable("Modifier") != null) + { + TargetHealthManager.SetProgramVariable("Modifier", (totalDamage * -1)); + TargetHealthManager.SendCustomEvent("ModifyHealth"); + } + } + } + //legs handle blast this means that teoretically a player can rocket jump without taking damage + + //this is done locally by every player in the explosion + if(isVisible && hitCol.gameObject.name.Contains("legs")) + { + // localPlayer.SetVelocity(localPlayer.GetVelocity() + new Vector3(0, UpwardsModifier, 0)); + localPlayer.SetVelocity((localPlayer.GetPosition() - transform.position)/(localPlayer.GetPosition() - transform.position).magnitude * ExplosivePower * playerLaunchModifier + localPlayer.GetVelocity()); + if(localPlayer.GetVelocity().magnitude > MaxSpeedFromExplosionForPlayer) + { + localPlayer.SetVelocity(localPlayer.GetVelocity().normalized * MaxSpeedFromExplosionForPlayer); + } + } + } + } + } + Destroy(gameObject, 4.0f); + //transform.parent.gameObject.SetActive(false); + } +} diff --git a/Scripts/Explosive.cs.meta b/Scripts/Explosive.cs.meta new file mode 100644 index 0000000..338059f --- /dev/null +++ b/Scripts/Explosive.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cc1ce1ce045b333408ad0495574a6aa5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GripScript.cs b/Scripts/GripScript.cs new file mode 100644 index 0000000..79e76f0 --- /dev/null +++ b/Scripts/GripScript.cs @@ -0,0 +1,24 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +public class GripScript : UdonSharpBehaviour +{ + private Rigidbody body; + private void Start() + { + body = gameObject.GetComponent(); + } + + private void OnDrop() + { + body.isKinematic = false; + } + + private void OnPickup() + { + body.isKinematic = true; + } +} diff --git a/Scripts/GripScript.cs.meta b/Scripts/GripScript.cs.meta new file mode 100644 index 0000000..ec5bcba --- /dev/null +++ b/Scripts/GripScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 76bc69efa895a2a4ab4c6eb3616aed9a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Gun.cs b/Scripts/Gun.cs new file mode 100644 index 0000000..c9f7c1a --- /dev/null +++ b/Scripts/Gun.cs @@ -0,0 +1,366 @@ +using UdonSharp; +using UnityEngine; +using UnityEngine.UI; +using VRC.SDKBase; +using VRC.Udon; +using VRC.SDK3.Components; + +[AddComponentMenu("")] +public class Gun : UdonSharpBehaviour +{ + //projectiles will come in future, maybe... + public bool RaycastDamage = true; + public Transform LocalBulletPool; + + public float maxDistance; + public float RaycastDamageAmount; + //public LayerMask hitboxLayer; + public GameObject RaycastSpark; + public bool shotgun = false; + public int pelletCount; + public bool Automatic = false; + public GameObject bullet; + public Transform firePosition; + public float fireVelocity = 5f; + public int AmmoCount = 5; + public float reloadTime = 15f; + public AudioClip[] clips = new AudioClip[4]; + public Text Display; + public float BulletSpread = 10f; + public LayerMask sparkable; + public LayerMask players; + public VRC_Pickup pickup; + + public ScopeManager scope; + + private int MaxAmmo; + private bool startTimer = false; + private float currentTime; + private float wantedTime; + private bool AmmoCheck = true; + private new AudioSource audio; + private bool isreloadingaudio = true; + private VRCPlayerApi localPlayer; + + public Animator GunAnimator; + public AnimationClip CycleAnimation; + public bool UseShellParticle; + public ParticleSystem ShellParticle; + + private float firedTime; + public bool BaseCycleOffAnimation; + public float CycleTime; + + private string AnimName; + private bool Firing = false; + private bool Scoped; + public float recoilForce; + + public void OnPickupUseDown() + { + if (Automatic == true) + { + SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "SetFireTrue"); + } + else + { + SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "Fire"); + } + } + + public void OnPickupUseUp() + { + SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "SetFireFalse"); + } + + public void SetFireTrue() + { + Firing = true; + } + + public void SetFireFalse() + { + Firing = false; + } + private void Update() + { + + if (Firing == true) + { + if (Time.time - firedTime > CycleTime) + { + firedTime = Time.time; + Fire(); + } + } + + + } + + private void Start() + { + localPlayer = Networking.LocalPlayer; + audio = (AudioSource)gameObject.GetComponent(typeof(AudioSource)); + MaxAmmo = AmmoCount; + Debug.Log("Ammo Left: " + AmmoCount); + + AnimName = CycleAnimation.name; + + if(BaseCycleOffAnimation) + { + CycleTime = CycleAnimation.length; + } + if (shotgun && !RaycastDamage) + { + shotgun = false; + //bad user, no projectile shotguns + } + + if (scope != null) + { + Scoped = true; + } + } + public void OnPickup() + { + if(Scoped) + { + scope.ManageScope(); + } + } + + private void FixedUpdate() + { + if (AmmoCount > 0) + { + Display.text = (AmmoCount.ToString() + " / " + MaxAmmo.ToString()); + } + else + { + Display.text = "Reloading"; + } + + if (AmmoCount <= 0 && AmmoCheck) + { + audio.PlayOneShot(clips[1]); + Reload(); + AmmoCheck = false; + } + + if (!startTimer) return; + if (currentTime > wantedTime - 0.7 && isreloadingaudio) + { + audio.PlayOneShot(clips[2]); + isreloadingaudio = false; + } + if (currentTime < wantedTime) + { + currentTime += Time.fixedDeltaTime; + } + else + { + startTimer = false; + AmmoCount = MaxAmmo; + AmmoCheck = true; + audio.PlayOneShot(clips[3]); + isreloadingaudio = true; + Debug.Log("Reloaded. Ammo now: " + AmmoCount); + Display.text = (AmmoCount.ToString() + " / " + MaxAmmo.ToString()); + } + } + + public void Fire() + { + + if (AmmoCount > 0) + { + if(RaycastDamage) + { + + //raycast stuff + if(shotgun) + { + for (int i = 0; i <= pelletCount; i++) + { + Quaternion temp = firePosition.rotation; + firePosition.Rotate(Random.Range(-BulletSpread, BulletSpread), Random.Range(-BulletSpread, BulletSpread), Random.Range(-BulletSpread, BulletSpread)); + RaycastHit hit; + + if (Physics.Raycast(firePosition.position, firePosition.forward, out hit, maxDistance, players)&& localPlayer.IsOwner(gameObject)) + { + if (hit.transform.gameObject.name.Contains("hitbox")) + { + GameObject target = hit.collider.gameObject; + UdonBehaviour TargetBehaviour = (UdonBehaviour)target.GetComponent(typeof(UdonBehaviour)); + TargetBehaviour.SetProgramVariable("Modifier", (RaycastDamageAmount * -1)); + + TargetBehaviour.SendCustomEvent("ModifyHealth"); + + firePosition.rotation = temp; + } + } + if (Physics.Raycast(firePosition.position, firePosition.forward, out hit, maxDistance, sparkable)) + { + Debug.Log("raycast hit"); + GunAnimator.Play("Base Layer." + AnimName, 0, 0.25f); + if (hit.collider != null) + { + if (!hit.collider.isTrigger) + { + if(RaycastSpark != null) + { + var spark = VRCInstantiate(RaycastSpark); + spark.transform.position = hit.point; + spark.SetActive(true); + Debug.Log("wall hit"); + } + Debug.Log("wall hit"); + + } + } + } + + + } + GunAnimator.Play("Base Layer." + AnimName, 0, 0.25f); + AmmoCount--; + audio.PlayOneShot(clips[0]); + if (UseShellParticle) + { + ShellParticle.Play(); + } + } + else + { + RaycastHit hit; + + if (Physics.Raycast(firePosition.position, firePosition.forward, out hit, maxDistance, players) && localPlayer.IsOwner(gameObject)) + { + Debug.Log("player layer hit"); + if (hit.transform.gameObject.name.Contains("hitbox")) + { + GameObject target = hit.collider.gameObject; + UdonBehaviour TargetBehaviour = (UdonBehaviour)target.GetComponent(typeof(UdonBehaviour)); + Debug.Log("before Modification"); + TargetBehaviour.SetProgramVariable("Modifier", (RaycastDamageAmount * -1)); + Debug.Log("aftermodification"); + TargetBehaviour.SendCustomEvent("ModifyHealth"); + + } + } + if (Physics.Raycast(firePosition.position, firePosition.forward, out hit, maxDistance, sparkable)) + { + Debug.Log("raycast hit"); + GunAnimator.Play("Base Layer." + AnimName, 0, 0.25f); + if (hit.collider != null) + { + if (!hit.collider.isTrigger) + { + var spark = VRCInstantiate(RaycastSpark); + spark.transform.position = hit.point; + spark.SetActive(true); + Debug.Log("wall hit"); + + } + } + } + + GunAnimator.Play("Base Layer." + AnimName, 0, 0.25f); + AmmoCount--; + audio.PlayOneShot(clips[0]); + if (UseShellParticle) + { + ShellParticle.Play(); + } + } + + + + } + else + { + + //projectile stuff + if (shotgun == false) + { + GunAnimator.Play("Base Layer." + AnimName, 0, 0.25f); + + //bullet shooting + //TODO replace instantiation with localised object pools + + var bul = VRCInstantiate(bullet); + + + if(bul != gameObject) + { + bul.transform.SetParent(null); + bul.SetActive(true); + bul.transform.SetPositionAndRotation(firePosition.position, firePosition.rotation); + + bul.transform.Rotate(Random.Range(-BulletSpread, BulletSpread), Random.Range(-BulletSpread, BulletSpread), Random.Range(-BulletSpread, BulletSpread)); + + var bulletrb = (Rigidbody)bul.GetComponent(typeof(Rigidbody)); + bulletrb.velocity = (bul.transform.forward) * fireVelocity; + AmmoCount--; + audio.PlayOneShot(clips[0]); + + if (UseShellParticle) + { + ShellParticle.Play(); + } + }else + { + Debug.Log("bullet not available"); + } + + + } + else + { + //shotgun + + for (int i = 0; i <= pelletCount; i++) + { + var bul = VRCInstantiate(bullet); + bul.transform.parent = null; + + bul.transform.SetPositionAndRotation(firePosition.position, firePosition.rotation); + bul.transform.Rotate(Random.Range(-BulletSpread, BulletSpread), Random.Range(-BulletSpread, BulletSpread), Random.Range(-BulletSpread, BulletSpread)); + bul.SetActive(true); + var bulletrb = (Rigidbody)bul.GetComponent(typeof(Rigidbody)); + bulletrb.velocity = (bul.transform.forward) * fireVelocity; + } + GunAnimator.Play("Base Layer." + AnimName, 0, 0.25f); + AmmoCount--; + audio.PlayOneShot(clips[0]); + if (UseShellParticle) + { + ShellParticle.Play(); + } + } + } + if (!localPlayer.IsPlayerGrounded())//only does anything if in the air. + { + if(Networking.IsOwner(gameObject)) + { + Vector3 PlayerVel = localPlayer.GetVelocity(); + localPlayer.SetVelocity(PlayerVel - firePosition.forward * recoilForce); + } + + } + } + //Debug.Log("Ammo Left: " + AmmoCount); + } + + + + private void Reload() + { + // Debug.Log("Reloading"); + currentTime = Time.time; + wantedTime = currentTime + reloadTime; + startTimer = true; + } + + +} diff --git a/Scripts/Gun.cs.meta b/Scripts/Gun.cs.meta new file mode 100644 index 0000000..6a8de9f --- /dev/null +++ b/Scripts/Gun.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a93ae1b2d1785a945bb476c20a9a7176 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/HealthManager.cs b/Scripts/HealthManager.cs new file mode 100644 index 0000000..fa1c42a --- /dev/null +++ b/Scripts/HealthManager.cs @@ -0,0 +1,103 @@ +using System; +using UnityEngine; +using UdonSharp; +using VRC.SDKBase; +using VRC.Udon; +using System.Collections; + +// USE ONLY FOR NPC'S AND WORLD OBJECTS! PLAYERS USE DIFFERENT SCRIPT! + +[AddComponentMenu("")] +public class HealthManager : UdonSharpBehaviour +{ + public UdonBehaviour BuffManager; + public float CurrentHealth = 100.0f; + [HideInInspector] + public float RespawnHealth; + public GameObject Healthbar; + public Transform self; + public float Modifier = 0f; + //private String ObjectTag = "[Object]"; + + public bool RespawnTimer = true; + + public Transform RespawnPoint; + public Transform DeathPoint; + public float RespawnTime = 5f; + + private bool isTimerComplete = false; + private bool StartTimer = false; + private float currentTime; + private float wantedTime; + + private void Start() + { + RespawnHealth = CurrentHealth; + } + + public void ModifyHealth() + { + CurrentHealth += Modifier; + } + + private void Update() + { + Debug.Log("Health = " + CurrentHealth); + + Healthbar.SetActive(CurrentHealth < RespawnHealth); + + if (CurrentHealth <= 0f) + { + CurrentHealth = RespawnHealth; + Die(); + } + + if (!StartTimer) return; + if (currentTime < wantedTime) + { + currentTime += Time.deltaTime; + } + else + { + isTimerComplete = true; + StartTimer = false; + Die(); + } + } + + public void Die() + { + if (RespawnTimer) + { + if (!isTimerComplete) + { + self.SetPositionAndRotation(DeathPoint.position, DeathPoint.rotation); + } + else + { + isTimerComplete = false; + RespawnObject(); + BuffManager.SendCustomEvent("ResetBleeding"); + BuffManager.SendCustomEvent("ResetPoison"); + } + } + else + { + RespawnObject(); + BuffManager.SendCustomEvent("ResetBleeding"); + BuffManager.SendCustomEvent("ResetPoison"); + } + } + + private void RespawnObject() + { + self.SetPositionAndRotation(RespawnPoint.position, RespawnPoint.rotation); + } + + public void Timer() + { + currentTime = Time.time; + wantedTime = currentTime + RespawnTime; + StartTimer = true; + } +} diff --git a/Scripts/HealthManager.cs.meta b/Scripts/HealthManager.cs.meta new file mode 100644 index 0000000..8191892 --- /dev/null +++ b/Scripts/HealthManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4d1114f0a59b9624f858ce517fde6fc5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/LitterallyNothing.asset b/Scripts/LitterallyNothing.asset new file mode 100644 index 0000000..982e78b --- /dev/null +++ b/Scripts/LitterallyNothing.asset @@ -0,0 +1,29 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4f11136daadff0b44ac2278a314682ab, type: 3} + m_Name: LitterallyNothing + m_EditorClassIdentifier: + serializedUdonProgramAsset: {fileID: 11400000, guid: c7b913b24869d2f4bb5d3161192b1d8e, + type: 2} + udonAssembly: ".data_start\r\n\r\n \r\n\r\n.data_end\r\n\r\n.code_start\r\n\r\n\r\n.code_end\r\n" + assemblyError: + graphData: + name: + description: + nodes: [] + updateOrder: 0 + graphElementData: [] + viewTransform: + position: {x: 0, y: 0} + scale: 1 + version: 1.0.0 + showAssembly: 0 diff --git a/Scripts/LitterallyNothing.asset.meta b/Scripts/LitterallyNothing.asset.meta new file mode 100644 index 0000000..720322b --- /dev/null +++ b/Scripts/LitterallyNothing.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 39912109fb0668e458c0d71fa1354600 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Lookat.cs b/Scripts/Lookat.cs new file mode 100644 index 0000000..4f80e5c --- /dev/null +++ b/Scripts/Lookat.cs @@ -0,0 +1,58 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +public class Lookat : UdonSharpBehaviour +{ + public Transform m_Target; + [SerializeField] private Vector2 m_RotationRange; + [SerializeField] private float m_FollowSpeed = 1; + + private Vector3 m_FollowAngles; + private Quaternion m_OriginalRotation; + + protected Vector3 m_FollowVelocity; + + + // Use this for initialization + void Start() + { + + m_OriginalRotation = transform.localRotation; + } + + + void FollowTarget() + { + // we make initial calculations from the original local rotation + transform.localRotation = m_OriginalRotation; + + // tackle rotation around Y first + Vector3 localTarget = transform.InverseTransformPoint(m_Target.position); + float yAngle = Mathf.Atan2(localTarget.x, localTarget.z) * Mathf.Rad2Deg; + + yAngle = Mathf.Clamp(yAngle, -m_RotationRange.y * 0.5f, m_RotationRange.y * 0.5f); + transform.localRotation = m_OriginalRotation * Quaternion.Euler(0, yAngle, 0); + + // then recalculate new local target position for rotation around X + localTarget = transform.InverseTransformPoint(m_Target.position); + float xAngle = Mathf.Atan2(localTarget.y, localTarget.z) * Mathf.Rad2Deg; + xAngle = Mathf.Clamp(xAngle, -m_RotationRange.x * 0.5f, m_RotationRange.x * 0.5f); + var targetAngles = new Vector3(m_FollowAngles.x + Mathf.DeltaAngle(m_FollowAngles.x, xAngle), + m_FollowAngles.y + Mathf.DeltaAngle(m_FollowAngles.y, yAngle)); + + // smoothly interpolate the current angles to the target angles + m_FollowAngles = Vector3.SmoothDamp(m_FollowAngles, targetAngles, ref m_FollowVelocity, m_FollowSpeed); + + + // and update the gameobject itself + transform.localRotation = m_OriginalRotation * Quaternion.Euler(-m_FollowAngles.x, m_FollowAngles.y, 0); + } + + private void Update() + { + FollowTarget(); + } +} diff --git a/Scripts/Lookat.cs.meta b/Scripts/Lookat.cs.meta new file mode 100644 index 0000000..5ed703a --- /dev/null +++ b/Scripts/Lookat.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f81b2ee23798de4408901f88688bd330 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/PlayerHealthManager.cs b/Scripts/PlayerHealthManager.cs new file mode 100644 index 0000000..1665835 --- /dev/null +++ b/Scripts/PlayerHealthManager.cs @@ -0,0 +1,175 @@ +using System; +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +//USE ONLY FOR PLAYERS! OBJECTS AND NPCS USE A DIFFERENT SCRIPT + +[AddComponentMenu("")] +public class PlayerHealthManager : UdonSharpBehaviour +{ + public UdonBehaviour BuffManager; + public float CurrentHealth = 100.0f; + public float CurrentHunger = 100.0f; + public float RespawnHealth; + public float Modifier = 0f; + + private VRCPlayerApi localPLayer; + // private String PlayerTag = "[Player]"; + + public bool RespawnTimer = true; + [Header("respawn Related Stuff")] + public Transform RespawnPoint; + public Transform DeathPoint; + public float RespawnTime = 5f; + + private bool isTimerComplete = false; + private bool StartTimer = false; + private float currentTime; + private float wantedTime; + + [Header("team and damage releated stuff")] + [HideInInspector] public bool blue; + [HideInInspector] public bool red; + public bool unassignTeamOnDeath; + + + //time management for the hunger + [Header("hunger related variable")] + private float lastDepletion; + public bool hunger = true; + public float hungerInterval; + public float hungerConsumption; + public bool allowSatiation; + private bool satiated; + public float satiationTime; + public AudioSource hungerNoise; + [HideInInspector] public float addedHunger; + [HideInInspector] public bool Dead = false; + private float maxHunger; + private void Start() + { + RespawnHealth = CurrentHealth; + localPLayer = Networking.LocalPlayer; + maxHunger = CurrentHunger; + if(allowSatiation == false) + { + satiated = false; + } + } + + public void ModifyHealth() + { + CurrentHealth += Modifier; + } + + + + private void Update() + { + // Debug.Log("Player Health = " + CurrentHealth); + //hunger stuff + if (hunger == true) + { + // Debug.Log("hunger true"); + if (Time.time - lastDepletion > hungerInterval) + { + //Debug.Log("depleting Food"); + CurrentHunger -= hungerConsumption; + if(CurrentHunger <= 0.25*maxHunger&&hungerNoise != null) + { + hungerNoise.Play(); + } + if(CurrentHunger < 0) + { + CurrentHunger = 0; + CurrentHealth -= 30; + } + lastDepletion = Time.time; + } + + } + //health stuff + if (CurrentHealth <= 0f) + { + + + Die(); + } + + if (!StartTimer) return; + if (currentTime < wantedTime) + { + currentTime += Time.deltaTime; + } + else + { + isTimerComplete = true; + StartTimer = false; + } + + + } + + + + public void Die() + { + Dead = true; + + + if(unassignTeamOnDeath) + { + red = false; + blue = false; + } + if (RespawnTimer) + { + Timer(); + if (!isTimerComplete) + { + Dead = true; + if (DeathPoint != null) + { + localPLayer.TeleportTo(DeathPoint.position, DeathPoint.rotation); + } + + Debug.Log("You have died."); + } + else + { + isTimerComplete = false; + RespawnObject(); + BuffManager.SendCustomEvent("ResetBleeding"); + BuffManager.SendCustomEvent("ResetPoison"); + } + } + else + { + RespawnObject(); + BuffManager.SendCustomEvent("ResetBleeding"); + BuffManager.SendCustomEvent("ResetPoison"); + } + } + + public void RespawnObject() + { + Debug.Log("respawn Triggerd"); + localPLayer.TeleportTo(RespawnPoint.position, RespawnPoint.rotation); + CurrentHunger = 100.0f; + CurrentHealth = RespawnHealth; + Dead = false; + } + + public void Timer() + { + if(!StartTimer) + { + currentTime = Time.time; + wantedTime = currentTime + RespawnTime; + StartTimer = true; + } + + } +} \ No newline at end of file diff --git a/Scripts/PlayerHealthManager.cs.meta b/Scripts/PlayerHealthManager.cs.meta new file mode 100644 index 0000000..ad5a5fb --- /dev/null +++ b/Scripts/PlayerHealthManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5943e39c74e86ea4b87073e6e545b5fa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/ScopeManager.cs b/Scripts/ScopeManager.cs new file mode 100644 index 0000000..655f2b6 --- /dev/null +++ b/Scripts/ScopeManager.cs @@ -0,0 +1,25 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +public class ScopeManager : UdonSharpBehaviour +{ + public Transform ScopeCameraPosition; + public float CameraFOV; + private GameObject CameraObject; + private Camera ScopeCamera; + + private void Start() + { + CameraObject = GameObject.Find("ScopeCam"); + ScopeCamera = CameraObject.GetComponent(); + } + public void ManageScope() + { + ScopeCamera.fieldOfView = CameraFOV; + CameraObject.transform.SetPositionAndRotation(ScopeCameraPosition.position, ScopeCameraPosition.rotation); + CameraObject.transform.SetParent(ScopeCameraPosition); + } +} diff --git a/Scripts/ScopeManager.cs.meta b/Scripts/ScopeManager.cs.meta new file mode 100644 index 0000000..2067bfa --- /dev/null +++ b/Scripts/ScopeManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 641f1c8859c481443944230339ee9dcb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Spark.cs b/Scripts/Spark.cs new file mode 100644 index 0000000..c5b1ae1 --- /dev/null +++ b/Scripts/Spark.cs @@ -0,0 +1,15 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +[AddComponentMenu("")] +public class Spark : UdonSharpBehaviour +{ + public float Lifetime = 1f; + private void Start() + { + Destroy(gameObject, Lifetime); + } +} diff --git a/Scripts/Spark.cs.meta b/Scripts/Spark.cs.meta new file mode 100644 index 0000000..4742746 --- /dev/null +++ b/Scripts/Spark.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 00eb92c99cf2d0944981cd149db407f0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/StatManager.cs b/Scripts/StatManager.cs new file mode 100644 index 0000000..314bbdc --- /dev/null +++ b/Scripts/StatManager.cs @@ -0,0 +1,21 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; +using UnityEngine.UI; + +public class StatManager : UdonSharpBehaviour +{ + public PlayerHealthManager playerHealthManager; + public Image healthBar; + public Image hungerBar; + + public void Update() + { + hungerBar.fillAmount = playerHealthManager.CurrentHunger / 100; + healthBar.fillAmount = playerHealthManager.CurrentHealth / 100; + } + + +} diff --git a/Scripts/StatManager.cs.meta b/Scripts/StatManager.cs.meta new file mode 100644 index 0000000..5203ee0 --- /dev/null +++ b/Scripts/StatManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a7a9e444feeec574fadd4e7666470b68 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/improvedHitbox.meta b/Scripts/improvedHitbox.meta new file mode 100644 index 0000000..428b87b --- /dev/null +++ b/Scripts/improvedHitbox.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 87a488605d4dd7746a8ab91f1a3b9f34 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/improvedHitbox/DamageDetector.cs b/Scripts/improvedHitbox/DamageDetector.cs new file mode 100644 index 0000000..51cf484 --- /dev/null +++ b/Scripts/improvedHitbox/DamageDetector.cs @@ -0,0 +1,18 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +public class DamageDetector : UdonSharpBehaviour +{ + public ImprovedHitBoxManager manager; + public float DamageModifier; + [HideInInspector] public float Modifier=0; + + public void ModifyHealth() + { + Debug.Log("ModifyHealth Triggered, Damage applied"); + manager.attemptDamageApplication(DamageModifier * Modifier); + } +} diff --git a/Scripts/improvedHitbox/DamageDetector.cs.meta b/Scripts/improvedHitbox/DamageDetector.cs.meta new file mode 100644 index 0000000..9361d7c --- /dev/null +++ b/Scripts/improvedHitbox/DamageDetector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 93d4edeba45f0ce4b873ca6bd961bf0b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/improvedHitbox/ImprovedHitBoxAssigner.cs b/Scripts/improvedHitbox/ImprovedHitBoxAssigner.cs new file mode 100644 index 0000000..0989cfe --- /dev/null +++ b/Scripts/improvedHitbox/ImprovedHitBoxAssigner.cs @@ -0,0 +1,51 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +public class ImprovedHitBoxAssigner : UdonSharpBehaviour +{ + private VRCPlayerApi[] players = new VRCPlayerApi[80]; + public ImprovedHitBoxManager[] hitboxArray; + //hitbox assignement stuff + private void assignHitboxes() + { + VRCPlayerApi.GetPlayers(players); + for (int i = 0; i < players.Length; i++) + { + if (players[i] != null) + { + hitboxArray[i].gameObject.SetActive(true); + hitboxArray[i].SetAssignedPlayer(players[i]); + } + } + for (int i = 0; i < hitboxArray.Length; i++) + { + if(hitboxArray[i].assignedPlayer == null) + { + hitboxArray[i].gameObject.SetActive(false); + } + } + } + + private void Start() + { + assignHitboxes(); + } + private void OnPlayerJoined(VRCPlayerApi player) + { + assignHitboxes(); + } + private void OnPlayerLeft(VRCPlayerApi player) + { + for (int i = 0; i < hitboxArray.Length; i++) + { + if (hitboxArray[i].assignedPlayer == player) + { + hitboxArray[i].gameObject.SetActive(false); + } + } + //assignHitboxes(); + } +} diff --git a/Scripts/improvedHitbox/ImprovedHitBoxAssigner.cs.meta b/Scripts/improvedHitbox/ImprovedHitBoxAssigner.cs.meta new file mode 100644 index 0000000..ec4c7cf --- /dev/null +++ b/Scripts/improvedHitbox/ImprovedHitBoxAssigner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2853311e268bd147b981b274fa85928 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/improvedHitbox/ImprovedHitBoxManager.cs b/Scripts/improvedHitbox/ImprovedHitBoxManager.cs new file mode 100644 index 0000000..b7ff213 --- /dev/null +++ b/Scripts/improvedHitbox/ImprovedHitBoxManager.cs @@ -0,0 +1,88 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +public class ImprovedHitBoxManager : UdonSharpBehaviour +{ + + [Header("FOR THE LOVE OF GOD MAKE ME MANUAL SYNC")] + [HideInInspector] public VRCPlayerApi assignedPlayer; + + [UdonSynced(UdonSyncMode.None)] public float damageApplied; + + + // udon doesn't support syncing a VRCPlayerApi so to know who the player taking damage is we'll set them to own an empty gameobject + public GameObject playerSync; + public PlayerHealthManager healthManager; + VRCPlayerApi localplayer; + public improvedHitbox[] managedHitboxes; + public Transform HeadTransform; + + + //this is conflicting code you can delete savely but I can't + //public bool useBoxingSystem; + //public boxingHealth boxHealth; + + public void SetAssignedPlayer(VRCPlayerApi player) + { + + assignedPlayer = player; + for (int i = 0; i < managedHitboxes.Length; i++) + { + managedHitboxes[i].assignedPlayer = player; + } + } + + //damage application stuff + private void Start() + { + localplayer = Networking.LocalPlayer; + } + + public void attemptDamageApplication(float damage) + { + Debug.Log("Damage Applicaiton Attempted"); + damageApplied = damage; + Networking.SetOwner(assignedPlayer, playerSync); + RequestSerialization(); + SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "NetworkedDamage"); + } + public void NetworkedDamage() + { + // Debug.Log("reeeee"); + if(localplayer == Networking.GetOwner(playerSync)) + { + Debug.Log("networkedDamageApplied"); + + //this is conflicting code you can delete savely but I can't + /* + if(useBoxingSystem) + { + + if(boxHealth.guarding) + { + boxHealth.guard += damageApplied; + } + else + { + boxHealth.health += damageApplied; + } + + + boxHealth.currentStaminaSpooledRegenTime = Time.time; + boxHealth.currentStaminaSpooledRegenTime = 0.0f; + } + else + { + healthManager.CurrentHealth += damageApplied; + }*/ + + healthManager.CurrentHealth += damageApplied; + } + } + + +} + diff --git a/Scripts/improvedHitbox/ImprovedHitBoxManager.cs.meta b/Scripts/improvedHitbox/ImprovedHitBoxManager.cs.meta new file mode 100644 index 0000000..4c2ae6e --- /dev/null +++ b/Scripts/improvedHitbox/ImprovedHitBoxManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6143542d4f619064f9a41aab309c9dc7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/improvedHitbox/improvedHitbox.cs b/Scripts/improvedHitbox/improvedHitbox.cs new file mode 100644 index 0000000..8a2648e --- /dev/null +++ b/Scripts/improvedHitbox/improvedHitbox.cs @@ -0,0 +1,54 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; + +public class improvedHitbox : UdonSharpBehaviour +{ + public bool leg; + public bool torso; + public bool head; + private Transform col; + [HideInInspector] public VRCPlayerApi assignedPlayer; + public Transform thingy; + + private void Start() + { + col = transform; + } + //positional tracking based on what it is + private void Update() + { + if(assignedPlayer.IsValid()) + { + if (leg) + { + col.position = (assignedPlayer.GetBonePosition(HumanBodyBones.LeftFoot) + assignedPlayer.GetBonePosition(HumanBodyBones.RightFoot)) / 2; + //col.rotation = assignedPlayer.GetRotation(); + thingy.SetPositionAndRotation(assignedPlayer.GetBonePosition(HumanBodyBones.Hips), assignedPlayer.GetBoneRotation(HumanBodyBones.Hips)); + //col.LookAt(thingy); + float distance = Vector3.Distance(col.position, assignedPlayer.GetBonePosition(HumanBodyBones.Hips)) / 2; + col.localScale = new Vector3(1.0f, 1.0f, distance); + } + if (torso) + { + col.position = assignedPlayer.GetBonePosition(HumanBodyBones.Hips); + //col.rotation = assignedPlayer.GetBoneRotation(HumanBodyBones.Hips); + //getBoneTransform isn't available with udon, so I guess I'll just fucking make one with a position and rotation because apparently both of those are exposed to udon BUT NOT FUCKING getBoneTransform + thingy.SetPositionAndRotation(assignedPlayer.GetBonePosition(HumanBodyBones.Neck), assignedPlayer.GetRotation()); + //lookat constraint is dumb + //col.LookAt(thingy); + + + //fuck it, why not scale width too + col.localScale = new Vector3(1.0f, 1.0f, Vector3.Distance(assignedPlayer.GetBonePosition(HumanBodyBones.Hips), assignedPlayer.GetBonePosition(HumanBodyBones.Neck))); + } + if (head) + { + col.SetPositionAndRotation(assignedPlayer.GetBonePosition(HumanBodyBones.Head), assignedPlayer.GetBoneRotation(HumanBodyBones.Head)); + } + } + + } +} diff --git a/Scripts/improvedHitbox/improvedHitbox.cs.meta b/Scripts/improvedHitbox/improvedHitbox.cs.meta new file mode 100644 index 0000000..f859848 --- /dev/null +++ b/Scripts/improvedHitbox/improvedHitbox.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c332cebb1d8f0e048aa68a53fa4109ca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: