import { Vector2 } from "three/src/Three"; import { Component } from "../../hierarchy_object/Component"; import type { ReadonlyVector2 } from "../../math/ReadonlyVector2"; import { ContactPoint2D } from "../../physics/2d/ContactPoint2D"; import type { PhysicsMaterial2D } from "../../physics/2d/PhysicsMaterial2D"; import type { CollisionLayer, CollisionLayerParm } from "../../physics/CollisionLayer"; import type { Collider2D } from "./collider/Collider2D"; /** * The physical behaviour type of the Rigidbody2D. */ export declare enum RigidbodyType2D { Dynamic = 0, Kinematic = 1, Static = 2 } /** * Controls how collisions are detected when a Rigidbody2D moves. */ export declare enum CollisionDetectionMode2D { Discrete = 0, Continuous = 1 } /** * Settings for a Rigidbody2D's initial sleep state. */ export declare enum RigidbodySleepMode2D { NeverSleep = 0, StartAwake = 1, StartAsleep = 2 } /** * Option for how to apply a force using Rigidbody2D.AddForce. */ export declare enum ForceMode2D { Force = 0, Impulse = 1 } /** * Rigidbody physics component for 2D. * * Adding a Rigidbody2D component to a sprite puts it under the control of the physics engine. By itself, this means that the gameObject will be affected by gravity and can be controlled from scripts using forces. By adding the appropriate collider component, the sprite will also respond to collisions with other sprites. This behaviour comes entirely from physics system; very little code is required to get impressive and authentic physical behaviour and allows for "emergent" gameplay that was not explicitly coded into the game. * * * disallow multiple component */ export declare class RigidBody2D extends Component { readonly disallowMultipleComponent = true; private _physicsObject; private _body; private _bodyType; private _simulated; private _useAutoMass; private _mass; private _linearDrag; private _angularDrag; private _gravityScale; private _collisionDetection; private _sleepMode; private _freezeRotation; private _collisionLayer; private readonly _centerOfMass; private readonly _worldCenterOfMass; private _inertia; private readonly _linearVelocity; private _angularVelocity; awake(): void; onDestroy(): void; onEnable(): void; onDisable(): void; private updateCollidersFilter; private getPhysicsObject; private getB2Body; private readonly _massData; private updateMassData; /** * The physical behaviour type of the Rigidbody2D. (default: dynamic) */ get bodyType(): RigidbodyType2D; /** * The physical behaviour type of the Rigidbody2D. (default: dynamic) */ set bodyType(value: RigidbodyType2D); /** * The PhysicsMaterial2D that is applied to all Collider2D attached to this Rigidbody2D. (default: null) */ get material(): PhysicsMaterial2D | null; /** * The PhysicsMaterial2D that is applied to all Collider2D attached to this Rigidbody2D. (default: null) */ set material(value: PhysicsMaterial2D | null); /** * Indicates whether the rigid body should be simulated or not by the physics system. * * this value is same as the `enabled` property of the rigid body. */ get simulated(): boolean; /** * Indicates whether the rigid body should be simulated or not by the physics system. * * this value is same as the `enabled` property of the rigid body. */ set simulated(value: boolean); /** * Should the total rigid-body mass be automatically calculated from the [[Collider2D.density]] of attached colliders? (default: false) */ get useAutoMass(): boolean; /** * Should the total rigid-body mass be automatically calculated from the [[Collider2D.density]] of attached colliders? (default: false) */ set useAutoMass(value: boolean); /** * Mass of the Rigidbody. */ get mass(): number; /** * Mass of the Rigidbody. */ set mass(value: number); /** * Coefficient of drag. (default: 0) */ get drag(): number; /** * Coefficient of drag. (default: 0) */ set drag(value: number); /** * Coefficient of angular drag. (default: 0.05) */ get angularDrag(): number; /** * Coefficient of angular drag. (default: 0.05) */ set angularDrag(value: number); /** * The degree to which this object is affected by gravity. (default: 1) */ get gravityScale(): number; /** * The degree to which this object is affected by gravity. (default: 1) */ set gravityScale(value: number); /** * The method used by the physics engine to check if two objects have collided. (default: discrete) */ get collisionDetection(): CollisionDetectionMode2D; /** * The method used by the physics engine to check if two objects have collided. (default: discrete) */ set collisionDetection(value: CollisionDetectionMode2D); /** * The sleep state that the rigidbody will initially be in. (default: startAwake) */ get sleepMode(): RigidbodySleepMode2D; /** * The sleep state that the rigidbody will initially be in. (default: startAwake) */ set sleepMode(value: RigidbodySleepMode2D); /** * Controls whether physics will change the rotation of the object. (default: false) */ get freezeRotation(): boolean; /** * Controls whether physics will change the rotation of the object. (default: false) */ set freezeRotation(value: boolean); /** * get collision layer of this rigidbody as string. * @returns layer name */ getLayerToName(): CollisionLayerParm; /** * set collision layer of this rigidbody from string. * @param value layer name */ setLayerFromName(value: CollisionLayerParm): void; /** * collision layer of this rigidbody. (default: `CollisionLayerConst.DefaultLayer`) */ get layer(): number; /** * collision layer of this rigidbody. (default: `CollisionLayerConst.DefaultLayer`) */ set layer(value: number); /** * The center of mass of the rigidBody in local space. */ get centerOfMass(): ReadonlyVector2; /** * The center of mass of the rigidBody in local space. */ set centerOfMass(value: ReadonlyVector2); /** * Gets the center of mass of the rigidBody in global space. */ get worldCenterOfMass(): ReadonlyVector2; /** * The Rigidbody's resistance to changes in angular velocity (rotation). */ get inertia(): number; /** * The Rigidbody's resistance to changes in angular velocity (rotation). */ set inertia(value: number); /** * Linear velocity of the Rigidbody in units per second. */ get velocity(): ReadonlyVector2; /** * Linear velocity of the Rigidbody in units per second. */ set velocity(value: ReadonlyVector2); /** * Angular velocity in degrees per second. */ get angularVelocity(): number; /** * Angular velocity in degrees per second. */ set angularVelocity(value: number); /** * Returns the number of Collider2D attached to this Rigidbody2D. */ get attachedColliderCount(): number; private readonly _vec2Buffer; /** * Apply a force to the rigidbody. * @param force Components of the force in the X and Y axes. * @param mode The method used to apply the specified force. */ addForce(force: ReadonlyVector2, mode?: ForceMode2D): void; /** * Apply a force at a given position in space. * @param force Components of the force in the X and Y axes. * @param position Position in world space to apply the force. * @param mode The method used to apply the specified force. */ addForceAtPosition(force: ReadonlyVector2, position: ReadonlyVector2, mode?: ForceMode2D): void; /** * Adds a force to the rigidbody2D relative to its coordinate system. * @param relativeForce Components of the force in the X and Y axes. * @param mode The method used to apply the specified force. */ addRelativeForce(relativeForce: ReadonlyVector2, mode?: ForceMode2D): void; /** * Apply a torque at the rigidbody's centre of mass. * @param torque Torque to apply. * @param mode The force mode to use. */ addTorque(torque: number, mode?: ForceMode2D): void; /** * Get a local space point given the point `point` in rigidBody global space. * @param point The global space point to transform into local space. * @param out Receives the local space point. if this is `undefined`, a new Vector2 will be created. * @returns The local space point. */ getPoint(point: ReadonlyVector2, out?: Vector2): Vector2; /** * The velocity of the rigidbody at the point Point in global space. * * GetPointVelocity will take the angularVelocity of the rigidbody into account when calculating the velocity. * @param point The global space point to calculate velocity for. * @param out Receives the velocity. if this is `undefined`, a new Vector2 will be created. * @returns The velocity at the point. */ getPointVelocity(point: ReadonlyVector2, out?: Vector2): Vector2; /** * Get a global space point given the point `relativePoint` in rigidBody local space. * @param relativePoint The local space point to transform into global space. * @param out Receives the global space point. if this is `undefined`, a new Vector2 will be created. * @returns The global space point. */ getRelativePoint(relativePoint: ReadonlyVector2, out?: Vector2): Vector2; /** * The velocity of the rigidbody at the point `Point` in local space. * @param relativePoint The local space point to calculate velocity for. * @param out Receives the velocity. if this is `undefined`, a new Vector2 will be created. * @returns The velocity at the point. */ getRelativePointVelocity(relativePoint: ReadonlyVector2, out?: Vector2): Vector2; /** * Get a global space vector given the vector `relativeVector` in rigidBody local space. * @param relativeVector The local space vector to transform into a global space vector. * @param out Receives the global space vector. if this is `undefined`, a new Vector2 will be created. * @returns The global space vector. */ getRelativeVector(relativeVector: ReadonlyVector2, out?: Vector2): Vector2; /** * Get a local space vector given the vector `vector` in rigidBody global space. * @param vector The global space vector to transform into a local space vector. * @param out Receives the local space vector. if this is `undefined`, a new Vector2 will be created. * @returns The local space vector. */ getVector(vector: ReadonlyVector2, out?: Vector2): Vector2; /** * Returns all Collider2D that are attached to this Rigidbody2D. * * Calculates all Collider2D that are attached to this Rigidbody2D and returns them in the results array. * * if array size is not enough, it will be resized. * @param out An array of Collider2D used to receive the results. * @returns the number of Collider2D placed in the `out` array. */ getAttachedColliders(out: Collider2D[]): number; private readonly _worldManifold; /** * Retrieves all contact points for all of the Collider(s) attached to this Rigidbody. * @param out An array of ContactPoint2D used to receive the results. * @returns the number of ContactPoint2D placed in the `out` array. */ getContacts(out: ContactPoint2D[]): number; /** * Check if any of the Rigidbody2D colliders overlap a point in space. * @param point A point in world space. * @returns True if any of the colliders overlap the point, false otherwise. */ overlapPoint(point: ReadonlyVector2): boolean; /** * Is the rigidbody "sleeping"? * @returns True if the rigidbody is sleeping, false otherwise. */ isSleeping(): boolean; /** * Make the rigidbody "sleep". */ sleep(): void; /** * Is the rigidbody "awake"? * @returns True if the rigidbody is awake, false otherwise. */ isAwake(): boolean; /** * Make the rigidbody "awake". */ wakeUp(): void; }