Advertisement
Chaquator

Holo Gravity Stuff

Dec 6th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. @name HoloGravSimu
  2. @persist Count
  3. @persist E:entity
  4. @model models/props_junk/watermelon01.mdl
  5.  
  6. #Press your Walk Key (by default, Alt) to spawn holos
  7. #Press your Use Key (by default, E) to despawn holos.
  8.  
  9. if(first())
  10. {
  11. runOnKeys(owner(), 1)
  12.  
  13. E = entity()
  14. E["radius", number] = 75
  15.  
  16. function createGBody(Index, Base:entity)
  17. {
  18. local Offset = (randvec(-1, 1):setZ(0):normalized() * Base["radius", number])
  19. local H = holoCreate(Index, Base:pos() + Offset, vec(0.5))
  20. holoModel(Index, "hq_sphere")
  21. holoColor(Index, vec(255, 100, 0))
  22. holoDisableShading(Index, 1)
  23.  
  24. H:setTrails(5, 0, 10, "effects/beam_generic01", vec(255), 255)
  25.  
  26. H["vel", vector] = (Offset:cross(vec(0, 0, 1)):normalized() * sqrt(2400 / Base["radius", number])) #the sqrt(...) part makes it so it orbits in a perfect circle...
  27. }
  28.  
  29. function entity:bodyGravity(ForeignBody:entity, Gravity)
  30. {
  31. local GravF = (Gravity / (ForeignBody:pos():distance(This:pos()) ^ 2))
  32. local GravD = (ForeignBody:pos() - This:pos()):normalized()
  33.  
  34. This["vel", vector] = This["vel", vector] + (GravD * GravF)
  35. }
  36.  
  37. function handleGBody(Index, Base:entity, Gravity)
  38. {
  39. local H = holoEntity(Index)
  40.  
  41. H:bodyGravity(Base, Gravity)
  42.  
  43. holoPos(Index, H:pos() + H["vel", vector])
  44. }
  45.  
  46. timer("bodies", 100)
  47. }
  48.  
  49. if(clk("bodies"))
  50. {
  51. for(I = 1, Count)
  52. {
  53. handleGBody(I, E, 2400)
  54. }
  55.  
  56. timer("bodies", 100)
  57. }
  58.  
  59. if(keyClk(owner()))
  60. {
  61. if(owner():keyWalk())
  62. {
  63. Count++
  64. createGBody(Count, E)
  65.  
  66. print(4, toString(Count))
  67. }
  68. elseif(owner():keyUse())
  69. {
  70. if(Count > 0)
  71. {
  72. holoDelete(Count)
  73. Count--
  74. }
  75.  
  76. print(4, toString(Count))
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement