body_medium_impact_hard6.wav (ragdoll works)

This commit is contained in:
ecker 2026-05-22 22:23:42 -05:00
parent eec75781ba
commit 52b972167a
4 changed files with 22 additions and 19 deletions

View File

@ -206,19 +206,20 @@ ent:bind( "tick", function(self)
local forward = flattenedTransform.forward * heldObject.distance --flattenedTransform.orientation:rotate( Vector3f(0,0,1) ) local forward = flattenedTransform.forward * heldObject.distance --flattenedTransform.orientation:rotate( Vector3f(0,0,1) )
if heldObject.smoothSpeed ~= 0 then if heldObject.smoothSpeed ~= 0 then
local target = flattenedTransform.position + forward local heldObjectFlattened = heldObjectTransform:flatten()
local offset = target - heldObjectTransform.position
local delta = offset * time.delta() * heldObject.smoothSpeed
local distance = delta:norm() local target = flattenedTransform.position + forward
if distance > 0.001 then local offset = target - heldObjectFlattened.position
if timers.holp:elapsed() > 0.125 then
timers.holp:reset() local stiffness = 15.0
heldObjectPhysicsBody:setVelocity( delta * 20 ) local damping = 2.0
end local currentVelocity = heldObjectPhysicsBody:getVelocity()
else local mass = heldObjectPhysicsBody:getMass()
heldObjectPhysicsBody:setVelocity( Vector3f(0,0,0) )
end local springForce = offset * stiffness
local dampingForce = currentVelocity * -damping
heldObjectPhysicsBody:applyImpulse((springForce + dampingForce) * mass * time.delta())
else else
heldObjectTransform.position = flattenedTransform.position + forward heldObjectTransform.position = flattenedTransform.position + forward
end end
@ -236,7 +237,9 @@ ent:addHook( "entity:Use.%UID%", function( payload )
local propMetadata = prop:getComponent("Metadata") local propMetadata = prop:getComponent("Metadata")
if propMetadata["holdable"] then if propMetadata["holdable"] then
validUse = true 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.uid = payload.uid
heldObject.distance = offset:norm() heldObject.distance = offset:norm()

View File

@ -56,7 +56,7 @@ for k, _ in pairs( bodies ) do
body = physics.create( child, mass ) body = physics.create( child, mass )
body:asObb( OBB( Vector3f(), extent ) ) body:asObb( OBB( Vector3f(), extent ) )
body:setGravity( Vector3f( 0, 0, 0 ) ) --body:setGravity( Vector3f( 0, 0, 0 ) )
children[k] = child children[k] = child
bodies[k] = body bodies[k] = body

View File

@ -5,8 +5,8 @@
namespace binds { namespace binds {
namespace body { namespace body {
bool initialized( pod::PhysicsBody& self ) { return !!self.world; } bool initialized( pod::PhysicsBody& self ) { return !!self.world; }
pod::Vector3f& velocity( pod::PhysicsBody& self ) { return self.velocity; } pod::Vector3f& getVelocity( pod::PhysicsBody& self ) { return self.velocity; }
pod::Vector3f& angularVelocity( pod::PhysicsBody& self ) { return self.angularVelocity; } pod::Vector3f& getAngularVelocity( pod::PhysicsBody& self ) { return self.angularVelocity; }
void setVelocity( pod::PhysicsBody& self, const pod::Vector3f& v ) { uf::physics::setVelocity( self, v ); } 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 ); } 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_AND_COMPONENT(pod::PhysicsBody,
UF_LUA_REGISTER_USERTYPE_DEFINE( initialized, UF_LUA_C_FUN(::binds::body::initialized) ), 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( 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( 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( setAngularVelocity, UF_LUA_C_FUN(::binds::body::setAngularVelocity) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( applyAngularVelocity, UF_LUA_C_FUN(::binds::body::applyAngularVelocity) ), UF_LUA_REGISTER_USERTYPE_DEFINE( applyAngularVelocity, UF_LUA_C_FUN(::binds::body::applyAngularVelocity) ),

View File

@ -9,7 +9,7 @@
#include <uf/engine/scene/scene.h> #include <uf/engine/scene/scene.h>
#define UF_PHYSICS_TEST 1 #define UF_PHYSICS_TEST 0
pod::PhysicsSettings uf::physics::settings; pod::PhysicsSettings uf::physics::settings;