Advertisement
thegreen9

UNITY rojectile Prediction

Apr 4th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public static Vector2[] Plot(Rigidbody2D rigidbody, Vector2 pos, Vector2 velocity, int steps)
  6.  {
  7.      Vector2[] results = new Vector2[steps];
  8.  
  9.      float timestep = Time.fixedDeltaTime / Physics2D.velocityIterations;
  10.      Vector2 gravityAccel = Physics2D.gravity * rigidbody.gravityScale * timestep * timestep;
  11.      float drag = 1f - timestep * rigidbody.drag;
  12.      Vector2 moveStep = velocity * timestep;
  13.  
  14.      for (int i = 0; i < steps; ++i)
  15.      {
  16.          moveStep += gravityAccel;
  17.          moveStep *= drag;
  18.          pos += moveStep;
  19.          results[i] = pos;
  20.      }
  21.  
  22.      return results;
  23.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement