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

[Script] Collision Detection

1381114873
Lithl
Pro
Sheet Author
API Scripter
This is version 1 of my collision detection project. Currently, collision only works with polygons and polylines . This does include squares/rectangles, as they are stored in the same way. Additionally, the script does not currently account for resizing or rotating the collision paths. You may move a path around and the new location will be respected, but if you resize or rotate the path, the script will still collide with the initial size and orientation. Tokens which may only be controlled by a GM (ie: don't represent a character and have no controlling player, or represent a character which has no controlling player) will never collide with paths. Future versions of this script will account for other path types (ovals/circles and/or freehand paths), as well as account for resizing/rotation. Installation There are three configuration variables near the top of the script. You may alter them to customize the script functionality: coldtc.pathColor -- The script only considers paths of a specific color, allowing you to also use paths of other colors which your players will not collide with. By default, this is fuchsia; the color is specified as a hexadecimal web color, which you can see when selecting a color from the drawing interface. A path's fill color is ignored. coldtc.layer -- The script will only look at paths on the specified layer (map, objects, gmlayer, or walls). You can also set this value to "all" and paths on every layer will be considered. coldtc.behavior -- There are currently three different behaviors dictating how the script will act when a collision event occurs: coldtc.DONT_MOVE (return the token to its starting position), coldtc.WARN_PLAYER (sends a message warning that the token isn't supposed to be there), and coldtc.STOP_AT_WALL (the token will be moved 1 pixel away from the wall it collided with). You can combine multiple behaviors by using the bitwise OR operator, "|". Example: to use DONT_MOVE and WARN_PLAYER, the behavior should be set to "coldtc.DONT_MOVE|coldtc.WARN_PLAYER". STOP_AT_WALL overrides DONT_MOVE if both are set. Usage Notes The script can break if you go "warp speed" by holding an arrow key to move and you hit more than one wall before the script catches up. (If you drag a token through multiple walls, it will be stopped by the first one.) If a token gets stuck inside an area it shouldn't be in, the only fix is to make it a GM-only token (unlink it from a character and don't give any player control) and have a GM move the token back out. The script cannot detect who moved the token (the API does not expose that information), so if a token is set to be controlled by a GM specifically, it will still be subject to the collisions. Only a token with no controllers at all can freely move through walls. In most cases, the dynamic lighting will not update before the token's position is reset to the correct side of the wall (assuming a relevant behavior is set), meaning the player won't see what's on the other side (if the wall is on the DL layer or there's a similarly-positioned wall on the DL layer). However, sometimes the DL will update first, and the player will catch a glimpse of the other side. Remember: this version of the script only works with polygon paths: squares/rectangles, lines/polylines, and other open/closed polygons. Tokens will not collide with freehand drawings or ovals/circles. Code <a href="https://gist.github.com/Lithl/6861970" rel="nofollow">https://gist.github.com/Lithl/6861970</a>
My life is now complete.