Eonirr

trajectory projectile line

Apr 9th, 2025 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. private LineRenderer lineRenderer;
  2. public int lineResolution;
  3. public float launchForce = //same que l'addforce j'pense;
  4. public float gravity = // same que l'editor bg
  5.  
  6. void MakeTrajectory()
  7. {
  8. Vector3[] trajectoryPoints = new Vector3[lineResolution];
  9. Vector3 throwVelocity = startPoint.forward * launchForce;
  10.  
  11. for (int i = 0; i < lineResolution; i++)
  12. {
  13. float time = i * 0.1f;
  14. trajectoryPoints[i] = TrajectoryPoint(startPoint.position, throwVelocity, time);
  15. }
  16.  
  17. lineRenderer.positionCount = lineResolution;
  18. lineRenderer.SetPositions(trajectoryPoints);
  19. }
  20.  
  21. Vector3 TrajectoryPoint(Vector3 origin, Vector3 velocity, float time)
  22. {
  23. float x = velocity.x * time;
  24. float y = velocity.y * time + 0.5f * gravity * time * time;
  25. float z = velocity.z * time;
  26.  
  27. return new Vector3(x, y, z) + origin;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment