forked from LeenkxTeam/LNXSDK
added last needed important rigid body settings in the blender RB leenkx settings for game engine ? like min max velocity,damping and lock translation and rotationboolean settings
This commit is contained in:
@ -36,6 +36,18 @@ class RigidBody extends iron.Trait {
|
||||
var useDeactivation: Bool;
|
||||
var deactivationParams: Array<Float>;
|
||||
var ccd = false; // Continuous collision detection
|
||||
// New velocity limiting properties
|
||||
var linearVelocityMin: Float;
|
||||
var linearVelocityMax: Float;
|
||||
var angularVelocityMin: Float;
|
||||
var angularVelocityMax: Float;
|
||||
// New lock properties
|
||||
var lockTranslationX: Bool;
|
||||
var lockTranslationY: Bool;
|
||||
var lockTranslationZ: Bool;
|
||||
var lockRotationX: Bool;
|
||||
var lockRotationY: Bool;
|
||||
var lockRotationZ: Bool;
|
||||
public var group = 1;
|
||||
public var mask = 1;
|
||||
var trigger = false;
|
||||
@ -120,7 +132,17 @@ class RigidBody extends iron.Trait {
|
||||
collisionMargin: 0.0,
|
||||
linearDeactivationThreshold: 0.0,
|
||||
angularDeactivationThrshold: 0.0,
|
||||
deactivationTime: 0.0
|
||||
deactivationTime: 0.0,
|
||||
linearVelocityMin: 0.0,
|
||||
linearVelocityMax: 0.0,
|
||||
angularVelocityMin: 0.0,
|
||||
angularVelocityMax: 0.0,
|
||||
lockTranslationX: false,
|
||||
lockTranslationY: false,
|
||||
lockTranslationZ: false,
|
||||
lockRotationX: false,
|
||||
lockRotationY: false,
|
||||
lockRotationZ: false
|
||||
};
|
||||
|
||||
if (flags == null) flags = {
|
||||
@ -139,6 +161,18 @@ class RigidBody extends iron.Trait {
|
||||
this.angularFactors = [params.angularFactorsX, params.angularFactorsY, params.angularFactorsZ];
|
||||
this.collisionMargin = params.collisionMargin;
|
||||
this.deactivationParams = [params.linearDeactivationThreshold, params.angularDeactivationThrshold, params.deactivationTime];
|
||||
// New velocity limiting properties
|
||||
this.linearVelocityMin = params.linearVelocityMin;
|
||||
this.linearVelocityMax = params.linearVelocityMax;
|
||||
this.angularVelocityMin = params.angularVelocityMin;
|
||||
this.angularVelocityMax = params.angularVelocityMax;
|
||||
// New lock properties
|
||||
this.lockTranslationX = params.lockTranslationX;
|
||||
this.lockTranslationY = params.lockTranslationY;
|
||||
this.lockTranslationZ = params.lockTranslationZ;
|
||||
this.lockRotationX = params.lockRotationX;
|
||||
this.lockRotationY = params.lockRotationY;
|
||||
this.lockRotationZ = params.lockRotationZ;
|
||||
this.animated = flags.animated;
|
||||
this.trigger = flags.trigger;
|
||||
this.ccd = flags.ccd;
|
||||
@ -291,11 +325,25 @@ class RigidBody extends iron.Trait {
|
||||
}
|
||||
|
||||
if (linearFactors != null) {
|
||||
setLinearFactor(linearFactors[0], linearFactors[1], linearFactors[2]);
|
||||
// Apply lock properties by overriding factors
|
||||
var lx = linearFactors[0];
|
||||
var ly = linearFactors[1];
|
||||
var lz = linearFactors[2];
|
||||
if (lockTranslationX) lx = 0.0;
|
||||
if (lockTranslationY) ly = 0.0;
|
||||
if (lockTranslationZ) lz = 0.0;
|
||||
setLinearFactor(lx, ly, lz);
|
||||
}
|
||||
|
||||
if (angularFactors != null) {
|
||||
setAngularFactor(angularFactors[0], angularFactors[1], angularFactors[2]);
|
||||
// Apply lock properties by overriding factors
|
||||
var ax = angularFactors[0];
|
||||
var ay = angularFactors[1];
|
||||
var az = angularFactors[2];
|
||||
if (lockRotationX) ax = 0.0;
|
||||
if (lockRotationY) ay = 0.0;
|
||||
if (lockRotationZ) az = 0.0;
|
||||
setAngularFactor(ax, ay, az);
|
||||
}
|
||||
|
||||
if (trigger) bodyColl.setCollisionFlags(bodyColl.getCollisionFlags() | CF_NO_CONTACT_RESPONSE);
|
||||
@ -411,6 +459,55 @@ class RigidBody extends iron.Trait {
|
||||
var rbs = physics.getContacts(this);
|
||||
if (rbs != null) for (rb in rbs) for (f in onContact) f(rb);
|
||||
}
|
||||
|
||||
// Apply velocity limiting if enabled
|
||||
if (!animated && !staticObj) {
|
||||
applyVelocityLimits();
|
||||
}
|
||||
}
|
||||
|
||||
function applyVelocityLimits() {
|
||||
if (!ready) return;
|
||||
|
||||
// Check linear velocity limits
|
||||
if (linearVelocityMin > 0.0 || linearVelocityMax > 0.0) {
|
||||
var velocity = getLinearVelocity();
|
||||
var speed = velocity.length();
|
||||
|
||||
if (linearVelocityMin > 0.0 && speed < linearVelocityMin) {
|
||||
// Increase velocity to minimum
|
||||
if (speed > 0.0) {
|
||||
velocity.normalize();
|
||||
velocity.mult(linearVelocityMin);
|
||||
setLinearVelocity(velocity.x, velocity.y, velocity.z);
|
||||
}
|
||||
} else if (linearVelocityMax > 0.0 && speed > linearVelocityMax) {
|
||||
// Clamp velocity to maximum
|
||||
velocity.normalize();
|
||||
velocity.mult(linearVelocityMax);
|
||||
setLinearVelocity(velocity.x, velocity.y, velocity.z);
|
||||
}
|
||||
}
|
||||
|
||||
// Check angular velocity limits
|
||||
if (angularVelocityMin > 0.0 || angularVelocityMax > 0.0) {
|
||||
var angularVel = getAngularVelocity();
|
||||
var angularSpeed = angularVel.length();
|
||||
|
||||
if (angularVelocityMin > 0.0 && angularSpeed < angularVelocityMin) {
|
||||
// Increase angular velocity to minimum
|
||||
if (angularSpeed > 0.0) {
|
||||
angularVel.normalize();
|
||||
angularVel.mult(angularVelocityMin);
|
||||
setAngularVelocity(angularVel.x, angularVel.y, angularVel.z);
|
||||
}
|
||||
} else if (angularVelocityMax > 0.0 && angularSpeed > angularVelocityMax) {
|
||||
// Clamp angular velocity to maximum
|
||||
angularVel.normalize();
|
||||
angularVel.mult(angularVelocityMax);
|
||||
setAngularVelocity(angularVel.x, angularVel.y, angularVel.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function disableCollision() {
|
||||
@ -745,6 +842,16 @@ typedef RigidBodyParams = {
|
||||
var linearDeactivationThreshold: Float;
|
||||
var angularDeactivationThrshold: Float;
|
||||
var deactivationTime: Float;
|
||||
var linearVelocityMin: Float;
|
||||
var linearVelocityMax: Float;
|
||||
var angularVelocityMin: Float;
|
||||
var angularVelocityMax: Float;
|
||||
var lockTranslationX: Bool;
|
||||
var lockTranslationY: Bool;
|
||||
var lockTranslationZ: Bool;
|
||||
var lockRotationX: Bool;
|
||||
var lockRotationY: Bool;
|
||||
var lockRotationZ: Bool;
|
||||
}
|
||||
|
||||
typedef RigidBodyFlags = {
|
||||
|
Reference in New Issue
Block a user