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

Movement collision detection

1390400797

Edited 1390874907
Chad
Sheet Author
Greetings! This is now updated to version 1. This is a stable version of the program. (Version 2 is in planning stages right now and will be coming sometime in the future once I have a chance to plan it out a bit more. Before I do that, I'll be working on a random dungeon generator.) Installation is simple. Just copy and paste the script and save it. The default options will work for most people. If you wish to issue chat commands, be sure to put your name in the correct settings lines. More detailed instructions are available within the script itself. Please read the comments starting at the top. How does it work? Whenever a player token is moved, a check is conducted to see if that player's token just completed a move that would intersect a path on screen. This works best on polygons of any size and shape and with acceptable accuracy on hand drawn walls. A similar check is made to see if the token ended in a space already holding another token. (Both of these checks can be toggled on or off in settings.) What's this weird algorithm at the end? It is really easy to tell if a line intersects another line. It's somewhat harder to tell if a line segment intersects another line segment. I know of four different algorithms that can be used, I chose this one because it's reliable and relatively easy to understand. More information is available online. This is the best site I've found: <a href="http://alienryderflex.com/intersect/" rel="nofollow">http://alienryderflex.com/intersect/</a> Here is the link to the Gist: File Link
1390417239

Edited 1390418058
Dude, this is hilariously awesome. I think this works if I import it into a already up and running campaign? It looks like it from CC.Paths, but I'm unfamiliar with if CC.Paths needs to be an actual defined function somewhere... (Not a javascript guru by any means. I ape scripts more than I write them). Screw being at work, imported and tested. Fun! Questions still remain though, leaving them up. A couple of questions to make sure I've got this down. This only hits on tokens that have a character sheet assigned to them? And if I turn the gmlayer off it won't cause issues currently with moving tokens around on the GM layer. This doesn't appear to work if you have a player on a page other than the default player page? Might cause some issues there. A suggestion for the .5 or higher version. Flag a token as ignore collision, for players that do things like ethereal jaunt. Regardless, you rock! As for the path deletion issue, is it faster to loop through the index and delete that one path, or just dump and re-register the entire path set?
1390427137
Chad
Sheet Author
Hi Brandon, Thanks for your thoughts. Yes, I was thinking the same thing about looping through all objects rather than setting an array and trying to track them that way. I have uploaded Version .5 to Gist and this is the procedure it is using now. From an efficiency standpoint, it uses less memory and, as long as "findObjs" is relatively efficient, it shouldn't have trouble. In answer to your other thoughts: Yes, this only hits on character tokens with a journal sheet attached. When I didn't limit that, it made it a real pain moving chairs and trees around. If there is a strong need, I can have it search for a particular attribute (eg "CheckCollision") on other types of tokens. I agree about the GM layer. I changed the GM layer default to false this time, it was too confusing having tokens hit walls that players can't see. By default, it triggers on background and lighting now. Right now it doesn't limit token by page, it pulls all of them up. So it should work for player tokens that have been moved to the GM page. I was actually thinking of disabling that though as I can't think of any reason that I'd want a character on the GM layer to hit walls. I like the idea of a way to flag tokens to ignore collision. Maybe an attribute called "Ethereal" or something. I'll look into it, won't bee too hard. Thanks!
1390432039

Edited 1390432095
Chad
Sheet Author
Updated to version .6: Version .6: - Added a check point for the center of the token - Set system to ignore tokens on GM layer - Fixed bug in token corner calculations that sometimes resulted in tokens being stuck inside walls.
1390434128
Chad
Sheet Author
And a quick update to version .7 at the request of a player of mine: Version .7: - Added 9 checkpoints to character token - Added options for override for center point - Set default to allow move if 4 checkpoints and the center are ok - Text output is now specific about why move failed
1390436946

Edited 1390445017
9 checkpoints means the larger a creature the further into a wall it can go before getting bounced unless you lock it down to a high number of checkpoints. Additionally, you've got an issue where if I split a character off onto a different map he's still bound by the walls on the primary campaign player map. As a quick fix, you might want to throw a check in there to validate that the player's current page equals the campaign player page id. Also for note, roll20 has issues about caching gists. It takes days for them to drop a cache'd gist and pick up the fact that you've made changes. --Edit As for the ethereal, you can always test for the presence of a specific statusmarker. If they're marked, they go through walls.
1390458626

Edited 1390458691
Alex L.
Pro
Sheet Author
You can fix the cache'd gist thing by linking to the latest revision not the main page. Click Revisions (on the left) then "View Gist @ [rev number]" then link the resulting page (it helps to edit out the link then same the edit then edit again to put the new link in). Also using this you can link to a stable revision while still editing so people dont get your test versions.
1390460132

Edited 1390460991
Chad
Sheet Author
Thanks Alex! Hi Brandon, You have good thoughts. I've actually started adjusting my version due to some of what you mentioned. I decided I needed a new set of options to get the job done right. The idea is to allow people to "squeeze through" narrow areas... but when you allow success on a match &lt; 9 points, you risk the chance of people edging themselves into a place where they are then stuck, which is no fun at all. When testing, we've found a number of combinations of options that result in this kind of problem, so I'm changing the option set completely along with some minor changes to the algorithm. My new option set lets you specify a width that must be available. For example, specifying that tokens can only move through spaces half their width (.5 ratio) or larger. Or even specifying that tokens need more than their width to move somewhere, such as 10% more (1.10 ratio). Then the algorithm will do a check from the 9 points based on that ratio. (Though I will keep the option of just checking the center point for those who want it. That works well for some types of games.) No longer will there be an option to specify how many points must pass, that's what's allowing people to edge through walls and get stuck by dragging and dropping just a tiny bit at a time. The major advantage of the new option set is that someone can't become stuck in walls by slowly edging toward them. It also allows the type of configuration GMs might want as some games work well with people squeezing through small places and some do not. As for tokens split onto new pages, I don't do that so I never spotted it. Thanks for the heads up. I can limit that fairly easy by doing the paths search on pages that match the new page of the token instead of matching the old page. That way the token will be limited by the page it's on. I'll add that to the next version and if you could test it I'd appreciate it, I never split players off. Thanks! I'll update the Gist link.
Looking forward to the next version. For the moment, I've tossed this in to simulate the 'passing through walls' ability in your 'is this a player or gm layer' section if (obj.get('status_radioactive') == true) return; //Tokens tagged with the radioactive symbol can walk through walls.
1390542587
Chad
Sheet Author
Updated to Version .8: - In the previous version, certain combinations of custom settings could allow characters to slowly edge themselves into a place that they couldn't escape. To avoid this, I simplified the settings into one "Detection Level". - Adjusted path search to make sure that tokens will only collide with walls on their current page (Useful for games where the GM splits players among pages.) - Added a new feature - Tokens are no longer able to end their move on top of another token. - Added check to see if tokens are ethereal. Ethereal tokens can pass thru walls but cannot end their move on top of another token. - Added chat commands to add and remove Ethereal from a token - Added option to check or not check walls and token collision
1390563263

Edited 1390570848
Cool update. The split between pages function works perfectly. The only problem I see left with this is it doesn't check for way point usage, or at least not well. Using a token with waypoints, I can't walk around a wall, it just thinks that I tried to walk through it. --Edit Another possible issue. The Ethereal name check is done specifically on your displayed name. If you've swapped to an NPC name you have to remember to swap back. Is it possible to use the player ID instead?
1390604152
Chad
Sheet Author
My computer science background asserted itself in this update: Version .9: - Efficiency update. Adjusted to avoid checks that aren't needed. COMING IN FUTURE VERSIONS Version 1: - Version 1 is feature complete. Just doing a big check for any possible bugs before naming this Version 1 Version 2: - Ability to identify GM of game without having to look for (GM) in chat - Ability for GM to move a token anywhere without using a chat command - More text based commands for GM - Collision check when non-player tokens are moved
1390604335
Chad
Sheet Author
Brandon W. said: The only problem I see left with this is it doesn't check for way point usage, or at least not well. Using a token with waypoints, I can't walk around a wall, it just thinks that I tried to walk through it. Another possible issue. The Ethereal name check is done specifically on your displayed name. If you've swapped to an NPC name you have to remember to swap back. Is it possible to use the player ID instead? I've started looking at the waypoints list in the graphic object, and I think I can access it and use it fairly easy. I'll add that to the planned features for version 2 as well. I have a plan for how to track GM tells without looking at the name. It's linked into the work I'm doing to allow a GM to always move a token. (They both require that I find and store the GM playerid). Thanks!
1390690278
Chad
Sheet Author
I found a small bug in .9. Sometimes tokens of certain sizes can't walk past each other. Fixed in version 1 which will be up later.
1390849363
Chad
Sheet Author
Version 1 uploaded: - Fixed bug where certain token widths would round up and therefore be unable to pass each other.