Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Toly65 committed Aug 12, 2021
1 parent 7befcda commit fccce02
Show file tree
Hide file tree
Showing 35 changed files with 1,706 additions and 0 deletions.
109 changes: 109 additions & 0 deletions Scripts/BuffManager.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 11 additions & 0 deletions Scripts/BuffManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

181 changes: 181 additions & 0 deletions Scripts/Bullet.cs
Original file line number Diff line number Diff line change
@@ -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<Rigidbody>();
myCollider = GetComponent<Collider>();
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);

}

}
11 changes: 11 additions & 0 deletions Scripts/Bullet.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Scripts/Display.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 11 additions & 0 deletions Scripts/Display.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fccce02

Please sign in to comment.