public void Pull(PullableController pullable) { Rigidbody pullRigidbody = pullable.rigidbody; if (pullRigidbody == null) { return; } Vector3 toTarget = pullable.transform.position - transform.position; float distance = toTarget.magnitude; // Circular falloff. //float pull = Mathf.Sqrt(Radius * Radius - distance * distance) / Radius * Strength; // Linear falloff. float pull = Strength - (Strength / Radius) * distance; if (pull < 0) { PullSpecific = null; return; } // Do something with mass? //float mass = pullRigidbody.mass; pullRigidbody.AddForce(toTarget * -pull); }
public virtual IList <AttachmentController> DiscoverNearbyAttachable() { List <AttachmentController> nearby = new List <AttachmentController>(); Collider[] hitColliders = Physics.OverlapSphere(transform.position, PullRadius); foreach (Collider collider in hitColliders) { PullableController pullable = collider.transform.GetComponent <PullableController>(); if (pullable == null || pullable.CapturedBy != null) { continue; } AttachmentController attachment = collider.transform.GetComponent <AttachmentController>(); if (attachment == null) { continue; } HardpointController mounting = attachment.FindMountingHardpoint(); if (mounting == null || mounting.Attached != null) { continue; } nearby.Add(attachment); } return(nearby); }
void Update() { if (!Enabled) { return; } if (PullSpecific != null) { Pull(PullSpecific); } else if (EnableGeneralPull) { Collider[] hitColliders = Physics.OverlapSphere(transform.position, Radius); foreach (Collider collider in hitColliders) { PullableController pullable = collider.transform.GetComponent <PullableController>(); if (pullable == null || pullable.CapturedBy != null) { continue; } Pull(pullable); } } }
public virtual void PullAndAttach(HardpointController point, AttachmentController attachment, HardpointController attachmentPoint) { PullableController pullable = attachment.GetComponent <PullableController>(); if (pullable == null) { Debug.Log("Cannot pull object that is not pullable."); return; } PullObjectsController puller = point.GetComponent <PullObjectsController>(); if (puller == null) { //Debug.Log("Cannot pull and attach as there is no puller on the point."); Attach(point, attachment, attachmentPoint); DiscoverConnected(); return; } puller.PullSpecific = pullable; PullingTogether.Add(new PullTogether(point, attachment, attachmentPoint)); }