body_medium_impact_hard6.wav (ragdoll works)
This commit is contained in:
parent
eec75781ba
commit
52b972167a
@ -206,19 +206,20 @@ ent:bind( "tick", function(self)
|
||||
|
||||
local forward = flattenedTransform.forward * heldObject.distance --flattenedTransform.orientation:rotate( Vector3f(0,0,1) )
|
||||
if heldObject.smoothSpeed ~= 0 then
|
||||
local target = flattenedTransform.position + forward
|
||||
local offset = target - heldObjectTransform.position
|
||||
local delta = offset * time.delta() * heldObject.smoothSpeed
|
||||
local heldObjectFlattened = heldObjectTransform:flatten()
|
||||
|
||||
local distance = delta:norm()
|
||||
if distance > 0.001 then
|
||||
if timers.holp:elapsed() > 0.125 then
|
||||
timers.holp:reset()
|
||||
heldObjectPhysicsBody:setVelocity( delta * 20 )
|
||||
end
|
||||
else
|
||||
heldObjectPhysicsBody:setVelocity( Vector3f(0,0,0) )
|
||||
end
|
||||
local target = flattenedTransform.position + forward
|
||||
local offset = target - heldObjectFlattened.position
|
||||
|
||||
local stiffness = 15.0
|
||||
local damping = 2.0
|
||||
local currentVelocity = heldObjectPhysicsBody:getVelocity()
|
||||
local mass = heldObjectPhysicsBody:getMass()
|
||||
|
||||
local springForce = offset * stiffness
|
||||
local dampingForce = currentVelocity * -damping
|
||||
|
||||
heldObjectPhysicsBody:applyImpulse((springForce + dampingForce) * mass * time.delta())
|
||||
else
|
||||
heldObjectTransform.position = flattenedTransform.position + forward
|
||||
end
|
||||
@ -236,7 +237,9 @@ ent:addHook( "entity:Use.%UID%", function( payload )
|
||||
local propMetadata = prop:getComponent("Metadata")
|
||||
if propMetadata["holdable"] then
|
||||
validUse = true
|
||||
local offset = transform.position - prop:getComponent("Transform").position
|
||||
local heldObjectTransform = prop:getComponent("Transform")
|
||||
local heldObjectFlattened = heldObjectTransform:flatten()
|
||||
local offset = transform.position - heldObjectFlattened.position
|
||||
|
||||
heldObject.uid = payload.uid
|
||||
heldObject.distance = offset:norm()
|
||||
|
||||
@ -56,7 +56,7 @@ for k, _ in pairs( bodies ) do
|
||||
|
||||
body = physics.create( child, mass )
|
||||
body:asObb( OBB( Vector3f(), extent ) )
|
||||
body:setGravity( Vector3f( 0, 0, 0 ) )
|
||||
--body:setGravity( Vector3f( 0, 0, 0 ) )
|
||||
|
||||
children[k] = child
|
||||
bodies[k] = body
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
namespace binds {
|
||||
namespace body {
|
||||
bool initialized( pod::PhysicsBody& self ) { return !!self.world; }
|
||||
pod::Vector3f& velocity( pod::PhysicsBody& self ) { return self.velocity; }
|
||||
pod::Vector3f& angularVelocity( pod::PhysicsBody& self ) { return self.angularVelocity; }
|
||||
pod::Vector3f& getVelocity( pod::PhysicsBody& self ) { return self.velocity; }
|
||||
pod::Vector3f& getAngularVelocity( pod::PhysicsBody& self ) { return self.angularVelocity; }
|
||||
|
||||
void setVelocity( pod::PhysicsBody& self, const pod::Vector3f& v ) { uf::physics::setVelocity( self, v ); }
|
||||
void setAngularVelocity( pod::PhysicsBody& self, const pod::Quaternion<>& q, float dt = 0 ) { uf::physics::setAngularVelocity( self, q, dt ); }
|
||||
@ -194,12 +194,12 @@ UF_LUA_REGISTER_USERTYPE_AND_COMPONENT(pod::Ray,
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE_AND_COMPONENT(pod::PhysicsBody,
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( initialized, UF_LUA_C_FUN(::binds::body::initialized) ),
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( pod::PhysicsBody::velocity ),
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( pod::PhysicsBody::angularVelocity ),
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( getVelocity, UF_LUA_C_FUN(::binds::body::getVelocity) ),
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( setVelocity, UF_LUA_C_FUN(::binds::body::setVelocity) ),
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( applyVelocity, UF_LUA_C_FUN(::binds::body::applyVelocity) ),
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( getAngularVelocity, UF_LUA_C_FUN(::binds::body::getAngularVelocity) ),
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( setAngularVelocity, UF_LUA_C_FUN(::binds::body::setAngularVelocity) ),
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( applyAngularVelocity, UF_LUA_C_FUN(::binds::body::applyAngularVelocity) ),
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
#include <uf/engine/scene/scene.h>
|
||||
|
||||
#define UF_PHYSICS_TEST 1
|
||||
#define UF_PHYSICS_TEST 0
|
||||
|
||||
pod::PhysicsSettings uf::physics::settings;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user