Guest User

e2fizykdirang

a guest
Dec 5th, 2021
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. @name Stabilization
  2. @persist E:entity A:angle
  3.  
  4.  
  5. if(first()){
  6.     Chip = entity()
  7.     E = propSpawn("models/props_junk/Wheebarrow01a.mdl", Chip:pos() + Chip:up() * 50, 0)
  8.     E:propGravity(0)
  9. }
  10.  
  11. #E is the stabilized entity
  12. #A is the target angle
  13.  
  14. runOnTick(1)
  15.  
  16. TarQ = quat(E:vel():normalized():toAngle()) #Calculate quaternion for target orientation
  17. CurQ = quat(E) #Calculate current orientation quaternion
  18.  
  19. #TarQ/CurQ is a quaternion representing the rotation that will rotate the object from current orientation to the target one.
  20. Q = TarQ/CurQ
  21.  
  22. #applyTorque() works on intrinsic vectors! Get the rotation vector and transform it.
  23. V = E:toLocal(rotationVector(Q)+E:pos())
  24. #Alternatively, can use "V = transpose(matrix(E))*rotationVector(Q)"
  25.  
  26. #Apply torque. angVelVector() works like a delta term.
  27. #Factors 150 and 12 can be adjusted to achieve best effect.
  28. E:applyTorque((150*V - 12*E:angVelVector())*E:inertia())
  29.  
  30. #This is only to stop movement, but it won't make the object float.
  31. #Disable gravity for the entity or write some code for floating if you want to see how this expression works.
  32. #E:applyForce(-E:vel()*E:mass())
  33.  
Advertisement
Add Comment
Please, Sign In to add comment