Using Tables to calculate distance of bouncing object
I'm trying to calculate the distance of an actor that is moving around the screen and colliding with walls. I can easily calculate the distance my actor travels if it does not collide with any walls, however, I'm running into trouble calculating the total distance traveled by the actor.
MY GOAL
What I want to do is calculate the distance from the initial position x, and initial position y, to the point where the actor collides with a wall (2nd position X and 2nd position Y). Then I want calculate the distance from 2nd position X and 2nd position Y to the final resting place of the actor final position X and final position Y, and sum the two distances. Once this code is written I imagine it will be easy to extrapolate and calculate the distance traveled for an infinite number of bounces on a wall.
WHAT I'VE TRIED
So far, I've constrained the traveling actor's position X and Y to to game attributes call puckX and puckY. I've also created a game attribute that will count the number of times the actor collides with a wall. Then I have created rules that will allow me to store these positions in a table. The tricky part is that I have not figured out how to sum the two distances, and I have not figured out how to erase these values after each shot. Ideally I'd like to store (at least in the background) the total distance the actor has traveled on one shot, and then clear/reset the table so that the same process can be repeated for the next shot.
Comments
Use Change Attribute to get the starting position x/y, a contact with the wall position x/y and where it bounces to finish position x/y. When you have these three sets of points use the magnitude() function to get the distance from start to wall and again for wall to finish and add them together.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Thanks, that worked. And I found out how to clear table values.