Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
E 1.72 KB | None | 0 0
  1. @inputs Ents:array Parent:entity
  2. interval(500)
  3.  
  4. #This doesn't work correctly
  5. function vector array:inertia(){
  6.     local Inertia = vec()
  7.     local Mass = 0
  8.     foreach (I, Entity:entity = This){
  9.         local EntMass = Entity:mass()
  10.         Inertia = Inertia + Entity:inertia() * EntMass
  11.         Mass = Mass + EntMass
  12.     }
  13.     return Inertia / Mass
  14. }
  15.  
  16. function angle array:angVel(){
  17.     local Vel = vec()
  18.     local Mass = 0
  19.     foreach (I, Entity:entity = This){
  20.         local EntMass = Entity:mass()
  21.         Vel = Vel + Entity:vel() * EntMass
  22.         Mass = Mass + EntMass
  23.     }
  24.     return ang(Vel:z(), -Vel:x(), Vel:y()) / Mass
  25. }
  26.  
  27. # This works correctly
  28. function vector array:massCenter(){
  29.     local MassCenter = vec()
  30.     local Mass = 0
  31.     foreach (I, Entity:entity = This){
  32.         local EntMass = Entity:mass()
  33.         MassCenter = MassCenter + Entity:massCenter() * EntMass
  34.         Mass = Mass + EntMass
  35.     }
  36.     return MassCenter / Mass
  37. }
  38.    
  39. function entity:applyOffsetAngForce(AngForce:angle, Position:vector){
  40.     local Up = This:up()
  41.     local Left = -This:right()
  42.     local Forward = This:forward()
  43.     if (AngForce:pitch() != 0){
  44.         local Pitch = Up * AngForce:pitch() * 0.5
  45.         This:applyOffsetForce(Forward, Position + Pitch)
  46.         This:applyOffsetForce(-Forward, Position - Pitch)
  47.     }
  48.     if (AngForce:yaw() != 0){
  49.         local Yaw = Forward * AngForce:yaw() * 0.5
  50.         This:applyOffsetForce(Left, Position + Yaw)
  51.         This:applyOffsetForce(-Left, Position - Yaw)
  52.     }
  53.     if (AngForce:roll() != 0){
  54.         local Roll = Left * AngForce:roll() * 0.5
  55.         This:applyOffsetForce(Up, Position + Roll)
  56.         This:applyOffsetForce(-Up, Position - Roll)
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement