/** * Update the position of the reticle */ private void UpdateReticle(Rigidbody target, GameObject reticle) { Vector3 targetVelocity = target.velocity; Vector3 relativePosition = target.transform.position - transform.position; float boltVelocity = (BoltForce / boltMass); float t = MathsUtils.CalculateInterceptTime(boltVelocity, relativePosition, targetVelocity); if (t <= 0) { reticle.transform.position = transform.position; reticle.transform.LookAt(actor.transform, actor.transform.up); //reticle.SetActive(false); } else { float reticleX = target.transform.position.x + (targetVelocity.x * t); float reticleY = target.transform.position.y + (targetVelocity.y * t); float reticleZ = target.transform.position.z + (targetVelocity.z * t); reticle.transform.position = new Vector3(reticleX, reticleY, reticleZ); reticle.transform.LookAt(actor.transform, actor.transform.up); //reticle.SetActive(true); } }
private float UpdatePrediction(GameObject prediction) { Vector3 targetVelocity = targetRigidbody.velocity; Vector3 targetPosition = Target.transform.position; float bulletVelocity = (BulletForce / BulletMass); float t = MathsUtils.CalculateInterceptTime(bulletVelocity, targetPosition, targetVelocity); if (t <= 0) { prediction.transform.position = BulletOrigin.transform.position; } else { float aimX = Target.transform.position.x + (targetVelocity.x * t); float aimY = Target.transform.position.y + (targetVelocity.y * t); float aimZ = Target.transform.position.z + (targetVelocity.z * t); prediction.transform.position = new Vector3(aimX, aimY, aimZ); } return(t); }