private void ShootTrajectoryCast(CharacterShooter shooter, float deviation, CharacterShooter.ShotType shotType) { TrajectoryRenderer.TrajectoryResult result = this.GetTrajectoryResult(shooter); if (result.hit.collider) { Vector3 pointA = result.hit.point; Vector3 pointB = result.hit.point; if (result.points.Length > 2) { pointA = result.points[result.count - 2]; pointB = result.points[result.count - 1]; } Vector3 direction = (pointA - pointB).normalized; Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, direction); GameObject other = result.hit.collider.gameObject; this.ExecuteShootActions( other, result.hit.point, rotation ); IgniterOnReceiveShot[] igniters = other.GetComponentsInChildren <IgniterOnReceiveShot>(); foreach (IgniterOnReceiveShot igniter in igniters) { if (igniter) { igniter.OnRecevieShot(shooter, shotType); } } if (!Mathf.Approximately(this.pushForce, 0f) && result.hit.rigidbody && direction != Vector3.zero) { result.hit.rigidbody.AddForceAtPosition( -direction * this.pushForce, result.hit.point, ForceMode.Impulse ); } if (this.prefabImpactEffect) { GameObject impact = PoolManager.Instance.Pick(this.prefabImpactEffect); impact.transform.SetPositionAndRotation(result.hit.point, rotation); } this.shootTrail.position1 = shooter.muzzle.GetPosition(); this.shootTrail.position2 = result.hit.point; } if (this.shootTrail.useShootingTrail) { ShootingTrailRenderer.Create(this.shootTrail, result); } }
public static ShootingTrailRenderer Create( ShootingTrail data, TrajectoryRenderer.TrajectoryResult trajectory) { GameObject instance = new GameObject("ShootingTrailRenderer"); ShootingTrailRenderer trail = instance.AddComponent <ShootingTrailRenderer>(); trail.SetupShootingTrail(data); trail.lineRenderer.positionCount = trajectory.count; trail.lineRenderer.SetPositions(trajectory.points); trail.retract = (trajectory.count == 2); if (trail.retract) { trail.positionA = trajectory.points[0]; trail.positionB = trajectory.points[1]; } return(trail); }