private void DropDart(RayHit rayHit) { if (PrefabDart != null) { Vector3 source = rayHit.rayStart; Vector3 target = rayHit.hitPosition; VelocityTime vt = ComputeArc(source, target); Vector3 velocity = vt.v; float t = vt.t; if (t > 0) { Vector3 startDir = target - source; startDir.y = 0; startDir.Normalize(); Vector3 right = Vector3.Cross(Vector3.up, startDir); Quaternion startRot = Quaternion.LookRotation(startDir, right); var newObj = GameObject.Instantiate(PrefabDart, source, startRot, AttachRoot); var rigidBody = newObj.GetComponent <Rigidbody>(); if (rigidBody != null) { rigidBody.AddForce(velocity, ForceMode.VelocityChange); //rigidBody.velocity = velocity; newObj.AddComponent <AdjusterMoving>(); } else { newObj.transform.position = target; newObj.AddComponent <AdjusterFixed>(); } } } }
private void ShowDartArc() { bool show = false; var activePointers = FindActivePointers(); if (activePointers.Count > 0) { var focusPointer = activePointers[0]; int uiLayer = LayerMask.GetMask("UI"); if (focusPointer.Result.CurrentPointerTarget == null || ((1 << focusPointer.Result.CurrentPointerTarget.layer) & uiLayer) == 0) { Vector3 rayStart = focusPointer.Rays[0].Origin; Vector3 endPoint = focusPointer.Result.Details.Point; VelocityTime vt = ComputeArc(rayStart, endPoint); if (vt.t > 0) { ShowArc(rayStart, vt.v, vt.t); show = true; } } } lineRenderer.enabled = show; }