The primary way we influence an object's physics is via its RigidBody attribute. The RigidBody represents the physical mechanics of a solid object in space.
Here's an example of applying an impulse to make an object passing through a Trigger hop.
function Trigger:onEnter(obj)
obj:getRigidBody():applyCentralImpulse(vector3(0,2,0))
end
An impulse is an instantaneous, non-persisting force applied to an object to affect its momentum. In the above example, we apply an impulse that pushes the object upwards (x=0, y=2, z=0).
An object in motion will have both linear and/or angular velocity. Linear velocity is a 3-dimensional vector representing its direction and speed through space while angular velocity is a 3-dimensional vector that represents the object's rotation about its origin.
We can get the speed from the linear velocity vector by taking its length (or magnitude). In the following example, we simulate a simple wing-lift-behavior by adding a lift constant force when the speed of the object goes over 10.
function MeshEntity:onMove()
speed = self:getRigidBody():getLinearVelocity():length()
lift = speed - 10
if (lift < 0) then
lift = 0
end
self:getRigidBody().constantForce = vector3(0, lift, 0);
end
Comments
0 comments
Please sign in to leave a comment.