Physics World
These methods adjust the physics settings from the world menu. For more information, see the world options manual.
Function | Description |
---|---|
checkSphereCollision(position, radius, filter) |
Checks if anything collides with the sphere at the given position with the given radius. Filter has these possible values: “kAll”, “kSensor”, “kEnemy”, “kPlatform”, “kCoin”, “kCharacter”, value from Asset Attribute, Entity. |
disableDeactivation(value) |
When a dynamic body is not moved for a few seconds, it will go into sleep mode. In sleep mode, the physics engine skips the body’s simulation. Sleep mode can be disabled with this method. By default, sleep mode is be enabled. |
getSphereCollisions(position, radius, filter) |
Returns colliders with a sphere at the given position with the given radius. Filter has these possible values: “kAll”, “kSensor”, “kEnemy”, “kPlatform”, “kCoin”, “kCharacter”, value from Asset Attribute, Entity. |
rayTest(from, to, filter) |
Returns physics bodies that collide with a ray between the two given Vec3 coordinates. The object returned has the properties bodies and sensors. Optional filter has these possible values: “kAll”, “kSensor”, “kEnemy”, “kPlatform”, “kCoin”, “kCharacter”, value from Asset Attribute, Entity. |
setSubSteps(value) |
Sets the value of the sub steps setting in the world options menu. |
setTimeWarp(value) |
Sets the value of the time warp setting in the world options menu. |
subSteps() |
Returns the value of sub steps from the world options menu. |
timeWarp() |
Returns the value of time warp from the world options menu. |
checkSphereCollision(position, radius, filter)
Checks if anything collides with the sphere at the given position with the given radius. Filter has these possible values: “kAll”, “kSensor”, “kEnemy”, “kPlatform”, “kCoin”, “kCharacter”, value from Asset Attribute, entity.
Parameters
Vec3 position – the position of the sphere
number radius – the radius of the sphere
string filter – / AssetModel / Entity / optional: “kAll” the filter of items to look for
Returns
boolean true if there is a collision, false if not
disableDeactivation(value)
When a dynamic body is not moved for a few seconds, it will go into sleep mode. In sleep mode, the physics engine skips the body’s simulation. Sleep mode can be disabled with this method. By default, sleep mode is be enabled.
Parameters
boolean value – true to disable deactivation, false to enable it
getSphereCollisions(position, radius, filter)
Returns colliders with a sphere at the given position with the given radius. One use case for this method would be interating through all the colliders within a sphere and adding damage to them for an explosion. Filter has these possible values: “kAll”, “kSensor”, “kEnemy”, “kPlatform”, “kCoin”, “kCharacter”, “kGround”, value from Asset Attribute, entity.
Parameters
Vec3 position – the position of the sphere
number radius – the radius of the sphere
string filter – / AssetModel filter / Entity filter the filter of items to look for
Returns
Object with properties {bodies, sensors} – an array of bodies and an array of sensors within the sphere
rayTest(from, to, filter)
Returns physics bodies that collide with a ray between the two given Vec3 coordinates. Optionally takes a filter parameter which has these possible values: “kAll”, “kSensor”, “kEnemy”, “kPlatform”, “kCoin”, “kCharacter”, value from Asset Attribute, entity.
The object returned by this function has the properties {bodies, sensors} which are each arrays. The bodies and sensors objects have the properties {object, hitPoint}.
Parameters
Vec3 from – the starting coordinate
Vec3 to – the ending coordinate
string filter – / AssetModel filter / Entity filter the filter of items to look for
Returns
Object with properties {bodies, sensors}.
// choose an object as the Selected Character with ray testing. pt is where the user tapped. let ray = cam.screenRay(pt); let rtst = this.scene().physicsWorld().rayTest( ray.origin, ray.origin.add(ray.direction.scale(100)) ); for (let i = 0; i < rtst.bodies.length; ++i) { let hit = rtst.bodies[i]; Settings.selectedCharacter = hit.object.parentEntity().name(); return; }
setSubSteps(value)
Sets the value of the sub steps setting in the world options menu.
Parameters
number value – the new sub steps value
setTimeWarp(value)
Sets the value of the time warp setting in the world options menu.
Parameters
number value – the new time warp value
subSteps()
Returns the value of sub steps from the world options menu.
Returns
number the sub step value
timeWarp()
Returns the value of time warp from the world options menu.
Returns
number the time warp value