Methods
# fireRaycast(origin, direction, maxDistance) → {Geometry.RaycastResult}
Fires a ray from its origin in the direction and report entities that intersect
with it, given the parameter constraints.
This will return any characters, enemies, NPCs, and SOLID vectors caught in the path of the
raycast enclosing them inside an object.
If no layer is specified, the origin layer will be the player's current.
Parameters:
Name | Type | Description |
---|---|---|
origin |
type | The point of origin from which the ray will be cast. The object must contain the properties _x, _y, and optionally _layer. |
direction |
type | The direction the ray will be cast. It must be normalized. The object must contain the properties x and y. |
maxDistance |
type | The maximum distance up to which intersections will be found. This is an optional parameter defaulting to Infinity. If it's Infinity find all intersections. If it's negative find only first intersection (if there is one). If it's positive find all intersections up to that distance. |
An object containing all of the entities in the path of the raycast.
Example
var hits = rpgcode.fireRaycast({
_x: location.x,
_y: location.y,
_layer: location.layer // Optional
}, vector, 13);
hits["characters"].forEach(function(character) {
rpgcode.log(character);
});
hits["enemies"].forEach(function(sprite) {
rpgcode.log(sprite.enemy);
});
hits["npcs"].forEach(function(sprite) {
rpgcode.log(sprite.npc);
});
hits["solids"].forEach(function(solid) {
rpgcode.log(solid.distance);
rpgcode.log(solid.x);
rpgcode.log(solid.y);
});
rpgcode.endProgram();
# getAngleBetweenPoints(x1, y1, x2, y2) → {number}
Gets the angle between two points in radians.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | |
y1 |
number | |
x2 |
number | |
y2 |
number |
The angle between the points in radians.
number
Example
// Get the angle in radians between two points.
var angle = rpgcode.getAngleBetweenPoints(location.x, location.y, this.x, this.y);
# getDistanceBetweenPoints(x1, y1, x2, y2) → {number}
Gets the straight line distance between two points in pixels.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | |
y1 |
number | |
x2 |
number | |
y2 |
number |
The distance in pixels.
number
Example
// Get the distance between two points in pixels.
var distance = rpgcode.getDistanceBetweenPoints(location.x, location.y, this.x, this.y);
Type Definitions
Object
# RaycastResult
Properties:
Name | Type | Description |
---|---|---|
characters |
Array.<Asset.CharacterAsset> | |
enemies |
Array.<Asset.EnemyAsset> | |
npcs |
Array.<Asset.NpcAsset> | |
solids |
Array.<Geometry.Solid> |