Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. @name ARTILLERY_FINAL
  2. @inputs V1:vector Cannon:entity Speed Type Gyro
  3. @outputs Pitch Yaw Distance
  4. @persist D V21:vector V22:vector Sin Osin RX RY
  5. @trigger
  6. #My Final Artillery:
  7. #Input The Vector of the target and the Entity of the (to judge the firing point)
  8. #You can easily change the entity input to a vector of the firing point,
  9. #and then replace line 17 with "V22 = vec(vec2(V2))" assuming V2 is the input
  10. #Input the Speed of the Porjectile (in units/sec)
  11. #Input the type, as this equation uses Sine, there are 2 solutions for each distance,
  12. #By Setting Type to 0, a shallower shorter path is taken
  13. #By Setting Type to 1, a higher, longer path is taken (more "Artillery-like")
  14. #The expression will output Pitch of Firing, Yaw (what bearing to aim at) and the Distance between gun and Target)
  15. #This expression uses equations from Wikipedia's "Trajectory of a  projectile" page
  16. V21 = vec(vec2(V1))
  17. V22 = vec(vec2(Cannon:pos()))
  18. D = V21:distance(V22)
  19. Sin=asin((0.5*D)/(Speed^2))
  20. Osin=180-Sin
  21. if(Type){
  22. Pitch = 0.515*Osin}
  23. else{
  24. Pitch = 0.5*Sin}
  25. Distance = D
  26. RX = (V22:x()) - (V21:x())
  27. RY = (V22:y()) - (V21:y())
  28. Yaw = atan(RY/RX)-(Gyro-141.24)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement