Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void DrawCurrentTrajectory() {
- Vector2 position = transform.position;
- Vector2 direction = firePosition.position - transform.position;
- RaycastHit2D hit = Physics2D.Raycast(position, direction, maximumRayCastDistance);
- Debug.DrawLine(position, position + direction * maximumRayCastDistance, Color.red);
- if (hit) {
- Debug.DrawLine(position, hit.point, Color.green);
- Debug.DrawLine(hit.point, hit.point + hit.normal * 0.25f, Color.magenta);
- position = hit.point + hit.normal * 0.00001f;
- }
- }
- void DrawCurrentTrajectory() {
- Vector2 position = transform.position;
- Vector2 direction = firePosition.position - transform.position;
- for(int i = 0; i <= maximumReflectionCount; ++i) {
- RaycastHit2D hit = Physics2D.Raycast(position, direction, maximumRayCastDistance);
- if (hit) {
- Debug.DrawLine(position, hit.point, Color.green);
- Debug.DrawLine(hit.point, hit.point + hit.normal * 0.25f, Color.magenta);
- position = hit.point + hit.normal * 0.00001f;
- direction = Vector2.Reflect(direction, hit.normal);
- }
- }
- }
- public class RicochetTrajectory : MonoBehaviour
- {
- public Transform firePosition;
- public int maximumReflectionCount = 5;
- public float maximumRayCastDistance = 50f;
- LineRenderer lineRenderer;
- List<Vector3> reflectionPositions = new List<Vector3>();
- private void Awake() {
- lineRenderer = GetComponent<LineRenderer>();
- lineRenderer.startWidth = 0.1f;
- lineRenderer.endWidth = 0.1f;
- }
- void Update()
- {
- DrawCurrentTrajectory();
- }
- void DrawCurrentTrajectory() {
- reflectionPositions.Clear();
- Vector2 position = transform.position;
- Vector2 direction = firePosition.position - transform.position;
- reflectionPositions.Add(position);
- for(int i = 0; i <= maximumReflectionCount; ++i) {
- RaycastHit2D hit = Physics2D.Raycast(position, direction, maximumRayCastDistance);
- if (hit) {
- position = hit.point + hit.normal * 0.00001f;
- direction = Vector2.Reflect(direction, hit.normal);
- reflectionPositions.Add(position);
- }
- }
- lineRenderer.positionCount = reflectionPositions.Count;
- lineRenderer.SetPositions(reflectionPositions.ToArray());
- }
- }
- position = hit.point + hit.normal * 0.00001f;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement