Advertisement
Ozin

Vecdraw companions

Aug 28th, 2020 (edited)
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.27 KB | None | 0 0
  1. //companion snake
  2. set keepVD to true.
  3. lock cent to facing:vector * 5.
  4. set c to 15.
  5. set vd to list().
  6. for i in range(c) vd:add(vecdraw(facing:starvector * 15, facing:vector, hsva(1,1,1,(c-i)/c), "", 1, true, ((c-i)/c) * 0.4 + 0.15, false)).
  7. set gr to 0.004. //"gravity" - the force that it pulls toward "cent" position
  8. set rnd to 0.2. //random force applied every tick
  9. set dr to 0.02.  //drag
  10. set vd_v to facing:vector * random().
  11. set cam to addons:camera:flightcamera.
  12. set vw to 4.
  13.  
  14. //companion snake 2
  15. set vd2 to list().
  16. for i in range(c) vd2:add(vecdraw(facing:starvector * -15, facing:vector, hsva(1,1,1,(c-i)/c), "", 1, true, ((c-i)/c) * 0.4 + 0.1, false)).
  17. set gr2 to 0.02.set dr2 to 0.03.
  18. set vd_v2 to facing:vector.
  19.  
  20. when true then {
  21.     set wdt to vw / (vd[0]:start-cam:position):mag.
  22.     for i in range(c-1,0,1) {
  23.         set col to vd[i-1]:color. set col:a to ((c-i)/c)^2. set vd[i]:color to col.
  24.         set vd[i]:vec to (vd[i-1]:start - vd[i]:start) * 1.2.
  25.         set vd[i]:start to vd[i-1]:start.
  26.         set vd[i]:width to wdt.
  27.     }
  28.     set vd_v to vd_v + (vd[0]:start-cent) * random() * -gr + V(random()-0.5,random()-0.5,random()-0.5) * rnd +      vd_v:normalized*vd_v:sqrmagnitude * -dr.
  29.     set vd[0]:vec to vd_v * 3.
  30.     set vd[0]:start to vd[0]:start + vd_v.
  31.     set vd[0]:color to hsva(min(1,vd_v:mag/2),1,1,1).
  32.     set vd[0]:width to wdt.
  33.  
  34.     for i in range(c-1,0,1) {
  35.         set col to vd2[i-1]:color. set col:a to ((c-i)/c)^2. set vd2[i]:color to col.
  36.         set vd2[i]:vec to (vd2[i-1]:start - vd2[i]:start) * 1.2.
  37.         set vd2[i]:start to vd2[i-1]:start.
  38.         set vd2[i]:width to wdt.
  39.     }
  40.     set vd_v2 to vd_v2 + (vd2[0]:start-vd[0]:start) * -gr2 + vd_v2:normalized*vd_v2:sqrmagnitude * -dr2.
  41.     set vd2[0]:vec to vd_v2 * 3.
  42.     set vd2[0]:start to vd2[0]:start + vd_v2.
  43.     set vd2[0]:color to hsva(min(1,vd_v2:mag/2),1,1,1).
  44.     set vd2[0]:width to wdt.
  45.    
  46.     return keepVD.
  47. }
  48.  
  49.  
  50. //terrain bounce:
  51. when body:geopositionof(vd[0]:start):terrainheight > (vd[0]:start-body:position):mag - body:radius then { set vd_v to vxcl(up:vector, vd_v) + up:vector * vdot(up:vector, vd_v) * -0.6. return not rcs. }
  52. when body:geopositionof(vd2[0]:start):terrainheight > (vd2[0]:start-body:position):mag - body:radius then { set vd_v2 to vxcl(up:vector, vd_v2) + up:vector * vdot(up:vector, vd_v2) * -0.6. return not rcs. }
  53.  
  54. on keepVD clearvecdraws().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement