@rpgjs/physic
Version:
A deterministic 2D top-down physics library for RPG, sandbox and MMO games
129 lines • 3.36 kB
TypeScript
import { Entity } from './Entity';
import { Vector2 } from '../core/math/Vector2';
/**
* Constraint interface
*
* Constraints limit the motion of entities (springs, joints, etc.)
*/
export interface Constraint {
/**
* Updates the constraint
*
* @param deltaTime - Time step
*/
update(deltaTime: number): void;
}
/**
* Spring constraint between two entities
*
* Connects two entities with a spring that applies forces to maintain
* a target distance.
*
* @example
* ```typescript
* const spring = new SpringConstraint(entity1, entity2, 10, 0.5, 0.1);
* spring.update(1/60);
* ```
*/
export declare class SpringConstraint implements Constraint {
private entityA;
private entityB;
private restLength;
private springConstant;
private damping;
/**
* Creates a new spring constraint
*
* @param entityA - First entity
* @param entityB - Second entity
* @param restLength - Rest length of the spring
* @param springConstant - Spring constant (stiffness)
* @param damping - Damping coefficient
*/
constructor(entityA: Entity, entityB: Entity, restLength: number, springConstant: number, damping: number);
/**
* @inheritdoc
*/
update(_deltaTime: number): void;
/**
* Gets the current length of the spring
*
* @returns Current length
*/
getCurrentLength(): number;
}
/**
* Distance constraint between two entities
*
* Maintains a fixed distance between two entities using impulses.
*
* @example
* ```typescript
* const constraint = new DistanceConstraint(entity1, entity2, 10);
* constraint.update(1/60);
* ```
*/
export declare class DistanceConstraint implements Constraint {
private entityA;
private entityB;
private targetDistance;
private stiffness;
/**
* Creates a new distance constraint
*
* @param entityA - First entity
* @param entityB - Second entity
* @param targetDistance - Target distance to maintain
* @param stiffness - Constraint stiffness (0-1, higher = stiffer)
*/
constructor(entityA: Entity, entityB: Entity, targetDistance: number, stiffness?: number);
/**
* @inheritdoc
*/
update(_deltaTime: number): void;
/**
* Gets the current distance
*
* @returns Current distance
*/
getCurrentDistance(): number;
}
/**
* Anchor constraint (pins an entity to a point)
*
* @example
* ```typescript
* const anchor = new AnchorConstraint(entity, new Vector2(0, 0), 0.5);
* anchor.update(1/60);
* ```
*/
export declare class AnchorConstraint implements Constraint {
private entity;
private anchorPoint;
private stiffness;
/**
* Creates a new anchor constraint
*
* @param entity - Entity to anchor
* @param anchorPoint - Anchor point in world space
* @param stiffness - Constraint stiffness (0-1)
*/
constructor(entity: Entity, anchorPoint: Vector2, stiffness?: number);
/**
* @inheritdoc
*/
update(_deltaTime: number): void;
/**
* Sets the anchor point
*
* @param point - New anchor point
*/
setAnchorPoint(point: Vector2): void;
/**
* Gets the anchor point
*
* @returns Anchor point
*/
getAnchorPoint(): Vector2;
}
//# sourceMappingURL=constraints.d.ts.map