Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name Stabilization
- @persist E:entity A:angle
- if(first()){
- Chip = entity()
- E = propSpawn("models/props_junk/Wheebarrow01a.mdl", Chip:pos() + Chip:up() * 50, 0)
- E:propGravity(0)
- }
- #E is the stabilized entity
- #A is the target angle
- runOnTick(1)
- TarQ = quat(E:vel():normalized():toAngle()) #Calculate quaternion for target orientation
- CurQ = quat(E) #Calculate current orientation quaternion
- #TarQ/CurQ is a quaternion representing the rotation that will rotate the object from current orientation to the target one.
- Q = TarQ/CurQ
- #applyTorque() works on intrinsic vectors! Get the rotation vector and transform it.
- V = E:toLocal(rotationVector(Q)+E:pos())
- #Alternatively, can use "V = transpose(matrix(E))*rotationVector(Q)"
- #Apply torque. angVelVector() works like a delta term.
- #Factors 150 and 12 can be adjusted to achieve best effect.
- E:applyTorque((150*V - 12*E:angVelVector())*E:inertia())
- #This is only to stop movement, but it won't make the object float.
- #Disable gravity for the entity or write some code for floating if you want to see how this expression works.
- #E:applyForce(-E:vel()*E:mass())
Advertisement
Add Comment
Please, Sign In to add comment