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] Simple Script to Orientate Rotation

I wanted to have my tokens face the direction they are moving in so I came up with this:    on("change:graphic", function(obj, prev)     {         if(obj && prev && (obj.get('top') !== prev.top || obj.get('left') !== prev.left) )          {             if (prev.top > obj.get('top'))             {                 // Going North                 obj.set('rotation', 180);             } else if (prev.top < obj.get('top')) {                 // Going South                    obj.set('rotation',0);             } else if (prev.left > obj.get('left')) {                 // Going West                     obj.set('rotation', 90);             } else if (prev.left < obj.get('left')) {                 // Going East                     obj.set('rotation', 270);             }         } }); I'm going to expand on it for Northeast/Northwest/Southeast/Southwest calculations but it's too late and my brain can't take it right now. Thought I'd share this little snippet for anyone who might be interested in having this functionality.
What about walking backwards? 
1524948117
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I believe  there is a script for this already. You might want to check this out to see if you can cadge anything useful from it.
keithcurtis said: I believe  there is a script for this already. You might want to check this out to see if you can cadge anything useful from it. Ahh cool I'll check it out. Thanks keithcurtis!
I checked out the script and it does exactly what I was planning to do, facing set diagonally when moving diagonally.  Had to make a few adjustments to it. It wouldn't change facing if you only took a 5 foot step (move 1 square) and I have issues with this because I move my tokens with the arrow keys and tell my players to do the same and only drag & drop when moving diagonally. Also the default neutral position of tokens was set to facing north or "up" so had to change that to south. All in all a good script. I should have tried to find something like this before taking a go at it myself.
1524960155
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Roll20 forums are difficult to search, and the script is not in the index or the one-click. You would only know it existed by virtue of having read the forums regularly for a long time. I use google searches to find Roll20 threads.