public HVRStabTracker(HVRStabber stabber, HVRStabbable stabbable, HVRStabbableSettings settings, ConfigurableJoint joint, GameObject stabbedObject, Vector3 stabDirection, Transform tip, Collider[] stabbedColliders) { Stabber = stabber; Stabbable = stabbable; Settings = settings; Joint = joint; StabbedObject = stabbedObject; StabbedColliders = stabbedColliders; _stabberLength = stabber.Length; //use world in case stabber is scaled _canFullStab = true; _stabLocalPosition = Joint.connectedAnchor; _stabDirectionLocal = stabbedObject.transform.InverseTransformDirection(stabDirection); _tip = tip; _base = tip == stabber.Tip ? stabber.Base : stabber.Tip; _unstabThreshold = Stabber.Settings.UnstabThreshold; UpdateEntryAndExit(); if (Stabber.IsDualStabber || settings.CanBeImpaled || Stabber.CanRunThrough) { TryFindExitPoint(stabDirection, stabbedColliders); } }
void Awake() { if (!Settings) { Settings = ScriptableObject.CreateInstance <HVRStabbableSettings>(); } Settings.CheckCurve(); Stabbers = new List <HVRStabber>(); }
private ConfigurableJoint SetupStabJoint(HVRStabbableSettings settings, Transform tip, Rigidbody otherRB) { var joint = Rigidbody.gameObject.AddComponent <ConfigurableJoint>(); joint.autoConfigureConnectedAnchor = false; joint.axis = StabLineLocal.normalized; joint.secondaryAxis = HVRUtilities.OrthogonalVector(joint.axis); joint.yMotion = ConfigurableJointMotion.Locked; joint.zMotion = ConfigurableJointMotion.Locked; joint.angularXMotion = ConfigurableJointMotion.Locked; joint.angularYMotion = ConfigurableJointMotion.Locked; joint.angularZMotion = ConfigurableJointMotion.Locked; //if (IsDualStabber || CanRunThrough) //{ // joint.xMotion = ConfigurableJointMotion.Free; //} //else { joint.anchor = tip.localPosition; joint.xMotion = ConfigurableJointMotion.Limited; } var limit = joint.linearLimit; if (settings.LimitStabDepth) { limit.limit = settings.StabDepthLimit; } else { limit.limit = Length; //using world because local magnitude is affect by scaled objects if (IsDualStabber || CanRunThrough) { limit.limit += .3f; } } joint.linearLimit = limit; joint.connectedBody = otherRB; if (joint.connectedBody) { joint.connectedAnchor = joint.connectedBody.transform.InverseTransformPoint(tip.position); } else { joint.connectedAnchor = tip.position; } return(joint); }
public void Start() { Rigidbody = GetComponent <Rigidbody>(); if (StabAnything && !FallbackSettings) { FallbackSettings = ScriptableObject.CreateInstance <HVRStabbableSettings>(); } if (FallbackSettings) { FallbackSettings.CheckCurve(); } if (CollidersToIgnore == null || CollidersToIgnore.Length == 0) { CollidersToIgnore = GetComponentsInChildren <Collider>(); } if (!Settings) { Settings = ScriptableObject.CreateInstance <HVRStabberSettings>(); } if (!FallbackSettings) { FallbackSettings = ScriptableObject.CreateInstance <HVRStabbableSettings>(); } StabbedObjects = new List <GameObject>(Settings.AllowedStabs); StabbedStabbables = new List <HVRStabbable>(Settings.AllowedStabs); foreach (var sc in StabbingColliders) { if (sc.contactOffset > ContactOffset) { sc.contactOffset = ContactOffset; } } }