object:queryRegion()

Type Function
Object ParticleSystem
Library physics.*
Return value Array
Revision Release 2022.3683
Keywords queryRegion, physics, LiquidFun
See also physics.newParticleSystem()
object:rayCast()

Overview

This function is used to find the particles that intersect with an axis-aligned (non-rotated) box. This box is defined by an upper-left coordinate and a lower-right coordinate.

This function returns an array of tables describing each hit. The positions returned are in content space.

Syntax

ParticleSystem:queryRegion( upperLeftX, upperLeftY, lowerRightX, lowerRightY, hitProperties )
upperLeftX (required)

Number. The upper-left x coordinate for the box region.

upperLeftY (required)

Number. The upper-left y coordinate for the box region.

lowerRightX (required)

Number. The lower-right x coordinate for the box region.

lowerRightY (required)

Number. The lower-right y coordinate for the box region.

hitProperties (optional)

Table. Table of optional properties which can be applied to each particle in the region. Acceptable options include:

  • deltaX — The x position delta to apply to each particle.
  • deltaY — The y position delta to apply to each particle.
  • velocityX — The x velocity to apply to each particle.
  • velocityY — The y velocity to apply to each particle.
  • deltaVelocityX — The x velocity delta to apply to each particle.
  • deltaVelocityY — The y velocity delta to apply to each particle.

Result Properties

hits will be an array of elements containing these properties:

Example

local hits = ParticleSystem:queryRegion(
    10, 40,
    100, 160,
    { deltaVelocityY = -40 }  --apply delta Y velocity of -40 to each particle in region
)

if ( hits ) then

    -- There's at least one hit
    print( "Hit count: " .. tostring( #hits ) )

    -- Output the results
    for i,v in ipairs( hits ) do
        print( "Object position: ", v.x, v.y )
    end
else
    -- No hits in region
end