Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[API bug] Spawning custom beam-like FX, pointing right

1466012195

Edited 1466012245
Ada L.
Marketplace Creator
Sheet Author
API Scripter
When using spawnFxBetweenPoints(p1, p2, custFxId, pageid) for a saved custom FX, some strange behavior happens when the Y difference between the start and end points is 0 and the X difference is positive. When these conditions are met, the custom FX is projected up and to the right instead of straight to the right. If the Y difference is close to 0 but not exactly 0 (e.g. 0.0001 or -0.01), then it works fine (the FX is projected approximately straight to the right). This weird behavior doesn't happen at all for spawning built-in beam-like FX (e.g. beam-fire). 
1466020710
Phil B.
Forum Champion
Sheet Author
I just tried this out in one of my own games and am not seeing the issue you describe. This is the spawnFX code I used: spawnFxBetweenPoints({x: 500, y: 500}, {x: 515, y: 500}, '[custom beam fx id]', '[page id]'); When I use this the beam shoots straight to the right. Could this be caused by another piece of your API script?
1466027931

Edited 1466028744
Ada L.
Marketplace Creator
Sheet Author
API Scripter
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].
1466198025
Phil B.
Forum Champion
Sheet Author
I figured out why it was working for me, and not for you. My beam has an "angleRandom" of 1, where as your's is 0. This weird behavior is somehow tied to that. I don't have time to go digging into this at the moment, but I'm going to create a bug report for this and will tackle it at a later date. In the mean time, you can use "angleRandon": 1 and that should fix your issue.
1466198310
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Thanks for looking into it! I'll use your workaround for now.