class
Eagle::Physics2D::World
- Eagle::Physics2D::World
- Reference
- Object
Overview
A container that simulates bodies: gravity, collisions and contact resolution, plus spatial queries such as raycasts.
Defined in:
eagle/physics/world2d.crInstance Method Summary
-
#add(type : BodyType, position : Vec2, shape : Shape) : Body
Creates a body with one shape, adds it and returns it.
-
#add_body(b : Body) : Body
Adds an existing body and returns it.
-
#began : Array({Eagle::Physics2D::Body, Eagle::Physics2D::Body})
Pairs of bodies that started touching in the last step.
-
#bias_factor : Float32
How aggressively overlap is corrected each step, from 0 to 1.
-
#bias_factor=(bias_factor : Float32)
How aggressively overlap is corrected each step, from 0 to 1.
-
#bodies : Array(Eagle::Physics2D::Body)
Every body in the world.
-
#cell_size : Float32
Cell size of the broad-phase grid.
-
#cell_size=(cell_size : Float32)
Cell size of the broad-phase grid.
-
#clear : Nil
Removes every body.
-
#contact_begin : Eagle::Emitter(Body, Body)
Emitted during a step when two bodies start touching.
-
#contact_end : Eagle::Emitter(Body, Body)
Emitted during a step when two bodies stop touching.
-
#emit_contact_begin(*args) : Nil
Emitted during a step when two bodies start touching.
-
#emit_contact_end(*args) : Nil
Emitted during a step when two bodies stop touching.
-
#ended : Array({Eagle::Physics2D::Body, Eagle::Physics2D::Body})
Pairs of bodies that stopped touching in the last step.
-
#gravity : Vec2
Acceleration applied to dynamic bodies, in pixels per second squared.
-
#gravity=(gravity : Vec2)
Acceleration applied to dynamic bodies, in pixels per second squared.
-
#iterations : Int32
Solver iterations per step.
-
#iterations=(iterations : Int32)
Solver iterations per step.
-
#move_and_slide(body : Body, motion : Vec2, max_slides : Int32 = 4) : Array(Vec2)
Moves a body by motion, sliding along obstacles.
-
#on_contact_begin(&block : Body, Body -> Nil) : Proc(Body, Body, Nil)
Emitted during a step when two bodies start touching.
-
#on_contact_end(&block : Body, Body -> Nil) : Proc(Body, Body, Nil)
Emitted during a step when two bodies stop touching.
-
#position_correction : Float32
Extra positional correction after each step.
-
#position_correction=(position_correction : Float32)
Extra positional correction after each step.
-
#probe_floor(body : Body, up : Vec2, distance : Float32, max_angle : Float32) : Vec2 | Nil
Looks for ground within distance below the body without moving it.
-
#query_point(p : Vec2, mask : UInt32 = 4294967295_u32) : Array(Body)
Every body containing the point p.
-
#query_rect(r : Rect, mask : UInt32 = 4294967295_u32) : Array(Body)
Every body whose bounds overlap r.
-
#query_shape(shape : Shape, mask : UInt32 = 4294967295_u32) : Array(Body)
Every body overlapping a world-space shape, for area attacks and placement checks.
-
#raycast(origin : Vec2, direction : Vec2, max_distance : Number = 1e6, mask : UInt32 = 4294967295_u32, exclude : Body | Nil = nil) : RayHit | Nil
--- queries ------------------------------------------------------------- Casts a ray and returns the closest hit, or
nil. -
#remove_body(b : Body) : Nil
Removes a body.
-
#slop : Float32
Overlap, in pixels, that is allowed before correction kicks in.
-
#slop=(slop : Float32)
Overlap, in pixels, that is allowed before correction kicks in.
-
#step(dt : Float32) : Nil
Advances the simulation by dt seconds.
Instance Method Detail
Creates a body with one shape, adds it and returns it.
Pairs of bodies that started touching in the last step.
How aggressively overlap is corrected each step, from 0 to 1. Too high looks jittery.
How aggressively overlap is corrected each step, from 0 to 1. Too high looks jittery.
Cell size of the broad-phase grid. Around twice the size of a typical body works well.
Cell size of the broad-phase grid. Around twice the size of a typical body works well.
Emitted during a step when two bodies start touching.
world = Physics2D::World.new
world.on_contact_begin { |a, b| puts "#{a.tag} hit #{b.tag}" }
Emitted during a step when two bodies start touching.
world = Physics2D::World.new
world.on_contact_begin { |a, b| puts "#{a.tag} hit #{b.tag}" }
Pairs of bodies that stopped touching in the last step.
Acceleration applied to dynamic bodies, in pixels per second squared.
Solver iterations per step. More iterations make stacks steadier but cost more time.
Solver iterations per step. More iterations make stacks steadier but cost more time.
Moves a body by motion, sliding along obstacles. Returns the normals of the surfaces hit.
KinematicBody2D#move_and_slide wraps this.
Emitted during a step when two bodies start touching.
world = Physics2D::World.new
world.on_contact_begin { |a, b| puts "#{a.tag} hit #{b.tag}" }
Emitted during a step when two bodies stop touching.
Extra positional correction after each step. 0 relies on the velocity bias alone.
Extra positional correction after each step. 0 relies on the velocity bias alone.
Looks for ground within distance below the body without moving it. Returns the floor normal if a surface within max_angle of up is found.
Every body containing the point p.
Every body whose bounds overlap r.
Every body overlapping a world-space shape, for area attacks and placement checks.
--- queries -------------------------------------------------------------
Casts a ray and returns the closest hit, or nil. direction doesn't need to be
normalized. Pass exclude to ignore one body, such as the one casting.
Overlap, in pixels, that is allowed before correction kicks in. It prevents jitter at rest.
Overlap, in pixels, that is allowed before correction kicks in. It prevents jitter at rest.
Advances the simulation by dt seconds. Use a fixed dt for stable results.