Here's the part of my code where the problem is contained. function _spawnSavedFx(custFx, pageId, origin, direction) {
var p1 = {
x: origin[0],
y: origin[1]
};
// Is this a beam-like FX?
if(custFx.get('definition').angle === -1) {
var p2 = {
x: origin[0] + direction[0],
y: origin[1] + direction[1]
};
spawnFxBetweenPoints(p1, p2, custFx.get('_id'), pageId);
}
else
spawnFx(p1.x, p1.y, custFx.get('_id'), pageId);
}
I'm computing the second point from a vector so that the second point will always be calculated relative to the first point. If I replace the Y component of the vector is 0 and I replace it with a value close to, but not exactly 0, then it fires the effect approximately to the right. In all other cases, it fires in the correct direction specified by the vector. If I log the values of p1 and p2, they aren't appearing malformed at all and p2 is being calculated as direction[0] pixels to the right of p1. Log sample: {"x":875,"y":595} // p1
{"x":877,"y":595} // p2
In case it would help to reproduce the issue, here is the definition for the custom FX I am using: {
"angle": -1,
"angleRandom": 0,
"duration": 25,
"emissionRate": 1,
"endColour": [32, 0, 255, 0],
"endColourRandom": [0, 0, 60, 0],
"gravity": {"x":0.01, "y":0.1},
"lifeSpan": 20,
"lifeSpanRandom": 5,
"maxParticles": 100,
"size": 200,
"sizeRandom": 100,
"speed": 50,
"speedRandom": 10,
"startColour": [255, 255, 255, 0.1],
"startColourRandom": [0, 0, 0, 0]
}
The numbers I'm using for the vectors are very low, usually like [2,0] or even unit vectors. I isn't making a difference though if I use a direction of [2,0] or [20, 0].