Skip to main content

Contact

Description:

  Contacts are objects created to manage collisions in worlds.

type

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: Contact): string

Returns:

Return TypeDescription
stringThe type as a string.

Of

Type: Function.

Description:

  Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

Signature:

typeOf: function(self: Contact, type_name: string): boolean

Parameters:

ParameterTypeDescription
type_namestringThe name of the type to check for.

Returns:

Return TypeDescription
booleanTrue if the object is of the specified type, false otherwise.

release

Type: Function.

Description:

  Destroys the object's Lua reference. The object will be completely deleted if it's not referenced by any other LÖVE object or thread. This method can be used to immediately clean up resources without waiting for Lua's garbage collector.

Signature:

release: function(self: Contact): boolean
isValid: function(self: Contact): boolean

Returns:

Return TypeDescription
booleanTrue if the object was released by this call, false if it had been previously released.

getFixtures

Type: Function.

Description:

  Gets the two Fixtures that hold the shapes that are in contact.

Signature:

getFixtures: function(self: Contact): Fixture, Fixture

Returns:

Return TypeDescription
FixtureThe first Fixture.
FixtureThe second Fixture.

getChildren

Type: Function.

Description:

  Gets the child indices of the shapes of the two colliding fixtures. For ChainShapes, an index of 1 is the first edge in the chain. Used together with Fixture:rayCast or ChainShape:getChildEdge.

Signature:

getChildren: function(self: Contact): integer, integer

Returns:

Return TypeDescription
integerThe child index of the first fixture's shape.
integerThe child index of the second fixture's shape.

getPositions

Type: Function.

Description:

  Returns the contact points of the two colliding fixtures. There can be one or two points.

Signature:

getPositions: function(self: Contact): number...

Returns:

Return TypeDescription
number...The x coordinate of the first contact point.

getNormal

Type: Function.

Description:

  Get the normal vector between two shapes that are in contact. This function returns the coordinates of a unit vector that points from the first shape to the second.

Signature:

getNormal: function(self: Contact): number, number

Returns:

Return TypeDescription
numberThe x component of the normal vector.
numberThe y component of the normal vector.

getFriction

Type: Function.

Description:

  Get the friction between two shapes that are in contact.

Signature:

getFriction: function(self: Contact): number

Returns:

Return TypeDescription
numberThe friction of the contact.

setFriction

Type: Function.

Description:

  Sets the contact friction.

Signature:

setFriction: function(self: Contact, friction: number)

Parameters:

ParameterTypeDescription
frictionnumberThe contact friction.

resetFriction

Type: Function.

Description:

  Resets the contact friction to the mixture value of both fixtures.

Signature:

resetFriction: function(self: Contact)

getRestitution

Type: Function.

Description:

  Get the restitution between two shapes that are in contact.

Signature:

getRestitution: function(self: Contact): number

Returns:

Return TypeDescription
numberThe restitution between the two shapes.

setRestitution

Type: Function.

Description:

  Sets the contact restitution.

Signature:

setRestitution: function(self: Contact, restitution: number)

Parameters:

ParameterTypeDescription
restitutionnumberThe contact restitution.

resetRestitution

Type: Function.

Description:

  Resets the contact restitution to the mixture value of both fixtures.

Signature:

resetRestitution: function(self: Contact)

isEnabled

Type: Function.

Description:

  Returns whether the contact is enabled. The collision will be ignored if a contact gets disabled in the preSolve callback.

Signature:

isEnabled: function(self: Contact): boolean

Returns:

Return TypeDescription
booleanTrue if enabled, false otherwise.

setEnabled

Type: Function.

Description:

  Enables or disables the contact.

Signature:

setEnabled: function(self: Contact, enabled: boolean)

Parameters:

ParameterTypeDescription
enabledbooleanTrue to enable or false to disable.

isTouching

Type: Function.

Description:

  Returns whether the two colliding fixtures are touching each other.

Signature:

isTouching: function(self: Contact): boolean
getTangentSpeed: function(self: Contact): number
setTangentSpeed: function(self: Contact, speed: number)

Parameters:

ParameterTypeDescription
speednumberThe speed parameter.

Returns:

Return TypeDescription
boolean or numberTrue if they touch or false if not.