/** * Represents a single point of contact between two colliding rigid bodies in the physics * simulation. Each contact point stores detailed spatial information about the collision, * including both local and world space coordinates of the exact contact points on both entities, * the contact normal direction, and the collision impulse force. * * Contact points are generated by the physics engine during collision detection and are typically * accessed through a {@link ContactResult} object, which can contain multiple contact points for a * single collision between two entities. Multiple contact points commonly occur when objects * collide along edges or faces rather than at a single point. * * The impulse property can be particularly useful for gameplay mechanics that need to respond * differently based on the force of impact, such as damage calculations or sound effect volume. * * Contact points are pooled and reused by the physics system, so a contact point and its vectors * are only valid inside the event handler that receives them. Copy any values that are needed * later, for example with {@link Vec3#clone}. * * @example * // Access contact points from a collision event * entity.collision.on('contact', (result) => { * // Get the first contact point * const contact = result.contacts[0]; * * // Get the contact position in world space * const worldPos = contact.point; * * // Check how hard the collision was * if (contact.impulse > 10) { * console.log("That was a hard impact!"); * } * }); * * @category Physics */ export class ContactPoint { /** * Create a new ContactPoint instance. * * @param {Vec3} [localPoint] - The point on the entity where the contact occurred, in the * local space of its rigid body. * @param {Vec3} [localPointOther] - The point on the other entity where the contact occurred, * in the local space of the other entity's rigid body. * @param {Vec3} [point] - The point on the entity where the contact occurred, in world space. * @param {Vec3} [pointOther] - The point on the other entity where the contact occurred, in * world space. * @param {Vec3} [normal] - The normal vector of the contact on the other entity, in world * space. * @param {number} [impulse] - The total accumulated impulse applied by the constraint solver * during the last sub-step. Describes how hard two objects collide. Defaults to 0. * @ignore */ constructor(localPoint?: Vec3, localPointOther?: Vec3, point?: Vec3, pointOther?: Vec3, normal?: Vec3, impulse?: number); /** * The point on the entity where the contact occurred, in the local space of its rigid body. * That space has the entity's world position and rotation, with any * {@link CollisionComponent#linearOffset} and {@link CollisionComponent#angularOffset} * applied, and ignores the entity's scale. * * @type {Vec3} */ localPoint: Vec3; /** * The point on the other entity where the contact occurred, in the local space of the other * entity's rigid body (see {@link ContactPoint#localPoint}). * * @type {Vec3} */ localPointOther: Vec3; /** * The point on the entity where the contact occurred, in world space. * * @type {Vec3} */ point: Vec3; /** * The point on the other entity where the contact occurred, in world space. * * @type {Vec3} */ pointOther: Vec3; /** * The normal vector of the contact on the other entity, in world space. This vector points * away from the surface of the other entity at the point of contact. * * @type {Vec3} */ normal: Vec3; /** * The total accumulated impulse applied by the constraint solver during the last sub-step. * This value represents how hard two objects collided. Higher values indicate stronger impacts. * * @type {number} */ impulse: number; } import { Vec3 } from '../../../core/math/vec3.js';