Fixed some physics problems.
This commit is contained in:
parent
e31e25f9e5
commit
fa15fce4ef
@ -4,13 +4,14 @@
|
|||||||
const DEFAULT_SHIP_PHYSICS = {
|
const DEFAULT_SHIP_PHYSICS = {
|
||||||
maxLinearVelocity: 200,
|
maxLinearVelocity: 200,
|
||||||
maxAngularVelocity: 1.4,
|
maxAngularVelocity: 1.4,
|
||||||
linearForceMultiplier: 100,
|
linearForceMultiplier: 500,
|
||||||
angularForceMultiplier: 1.5,
|
angularForceMultiplier: 1.5,
|
||||||
linearFuelConsumptionRate: 0.00002778, // 1 minute at full thrust (60 Hz)
|
linearFuelConsumptionRate: 0.0002778, // 1 minute at full thrust (60 Hz)
|
||||||
angularFuelConsumptionRate: 0.0001389, // 2 minutes at full thrust (60 Hz)
|
angularFuelConsumptionRate: 0.0001389, // 2 minutes at full thrust (60 Hz)
|
||||||
linearDamping: 0.2,
|
linearDamping: 0.2,
|
||||||
angularDamping: 0.3, // Moderate damping for 2-3 second coast
|
angularDamping: 0.5, // Moderate damping for 2-3 second coast
|
||||||
alwaysActive: true // Prevent physics sleep (false may cause abrupt stops at zero velocity)
|
alwaysActive: true, // Prevent physics sleep (false may cause abrupt stops at zero velocity)
|
||||||
|
reverseThrustFactor: 0.3 // Reverse thrust at 50% of forward thrust power
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,6 +86,7 @@ export class GameConfig {
|
|||||||
linearDamping: config.shipPhysics.linearDamping ?? DEFAULT_SHIP_PHYSICS.linearDamping,
|
linearDamping: config.shipPhysics.linearDamping ?? DEFAULT_SHIP_PHYSICS.linearDamping,
|
||||||
angularDamping: config.shipPhysics.angularDamping ?? DEFAULT_SHIP_PHYSICS.angularDamping,
|
angularDamping: config.shipPhysics.angularDamping ?? DEFAULT_SHIP_PHYSICS.angularDamping,
|
||||||
alwaysActive: config.shipPhysics.alwaysActive ?? DEFAULT_SHIP_PHYSICS.alwaysActive,
|
alwaysActive: config.shipPhysics.alwaysActive ?? DEFAULT_SHIP_PHYSICS.alwaysActive,
|
||||||
|
reverseThrustFactor: config.shipPhysics.reverseThrustFactor ?? DEFAULT_SHIP_PHYSICS.reverseThrustFactor,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -119,10 +119,12 @@ export class InputControlManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enable pointer selection
|
// Enable pointer selection
|
||||||
|
console.log(`[InputControlManager] About to update pointer feature...`);
|
||||||
this.updatePointerFeature();
|
this.updatePointerFeature();
|
||||||
|
|
||||||
// Emit state change event
|
// Emit state change event
|
||||||
this.emitStateChange(requester);
|
this.emitStateChange(requester);
|
||||||
|
console.log(`[InputControlManager] ===== Ship controls disabled =====`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -71,21 +71,29 @@ export class ShipPhysics {
|
|||||||
// Only apply force if we haven't reached max velocity
|
// Only apply force if we haven't reached max velocity
|
||||||
if (currentSpeed < this._config.maxLinearVelocity) {
|
if (currentSpeed < this._config.maxLinearVelocity) {
|
||||||
// Get local direction (Z-axis for forward/backward thrust)
|
// Get local direction (Z-axis for forward/backward thrust)
|
||||||
const localDirection = new Vector3(0, 0, -leftStick.y);
|
const thrustDirection = -leftStick.y; // negative = forward, positive = reverse
|
||||||
|
const localDirection = new Vector3(0, 0, thrustDirection);
|
||||||
|
|
||||||
// Transform to world space
|
// Transform to world space
|
||||||
const worldDirection = Vector3.TransformNormal(
|
const worldDirection = Vector3.TransformNormal(
|
||||||
localDirection,
|
localDirection,
|
||||||
transformNode.getWorldMatrix()
|
transformNode.getWorldMatrix()
|
||||||
);
|
);
|
||||||
const force = worldDirection.scale(this._config.linearForceMultiplier);
|
|
||||||
|
|
||||||
// Apply force at center of mass to avoid unintended torque
|
// Apply reverse thrust factor: forward at full power, reverse at reduced power
|
||||||
// (applying at an offset point creates rotation, noticeable at zero linear velocity)
|
const thrustMultiplier = thrustDirection < 0
|
||||||
const thrustPoint = Vector3.TransformCoordinates(
|
? 1.0 // Forward thrust at full power
|
||||||
physicsBody.getMassProperties().centerOfMass,
|
: this._config.reverseThrustFactor; // Reverse thrust scaled down
|
||||||
transformNode.getWorldMatrix()
|
|
||||||
|
const force = worldDirection.scale(
|
||||||
|
this._config.linearForceMultiplier * thrustMultiplier
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Apply force at ship's world position (center of mass)
|
||||||
|
// Since we overrode center of mass to (0,0,0) in local space, the transform origin is the CoM
|
||||||
|
// Using getAbsolutePosition() instead of transforming CoM avoids gyroscopic coupling during rotation
|
||||||
|
const thrustPoint = transformNode.getAbsolutePosition();
|
||||||
|
|
||||||
physicsBody.applyForce(force, thrustPoint);
|
physicsBody.applyForce(force, thrustPoint);
|
||||||
|
|
||||||
// Consume fuel based on config rate (tuned for 1 minute at full thrust)
|
// Consume fuel based on config rate (tuned for 1 minute at full thrust)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user