Hi, I’ve been encountering issues with trying to coordinate logic with collision “ended”. Two examples:
Let’s say I am trying to decorate a christmas tree. The tree has a complex multi-element physics body (exported from Physics Editor).
Example 1: Snow falls from the sky and onto the tree.
Currently, I would like snow to fall vertically from the sky and land randomly somewhere on the tree’s physics body. My current method works as follows: When a snowflake/tree collision begins , I set a timer (called land timer ) with a random time, which upon timer completion will stop the snowflake in place and remove the physics body.
But here’s the tricky part… if the snowflake is no longer touching the tree… instead of stopping the snowflake outside the tree, I want it to continue falling again (either 1. offscreen, or 2. if it starts to touch the tree again… say a lower branch… resume the timer from above). I tried doing this by canceling the land timer upon collision ended. Unfortunately though, the timing hasn’t been working correctly. Sometimes snowflakes land just outside the tree’s physics body, which seems to mean that the collision ended phase is too late for me to cancel the land timer.
Example 2: Painting the tree.
Let’s say I have a big paint brush and would like to paint the tree. I’d like the paint to come from the tip of the brush, which is offset quite a bit from where I am touching. So, going with ideas inspired by this post, I tried to coordinate touch and collision events. I put a physics body on the tip of the brush , where I would like paint to come from. When the brush tip collide begins with the tree, I set a flag isColliding. When the collision ends , I set the flag to false. Then, in my brush " touch" handler, while I’m dragging the brush around, I use this flag to determine if I can draw on the tree or not (since I don’t want to paint anywhere but the tree). Unfortunately, I am getting issues where if I touch move quickly , it appears the isColliding flag is being set as false too late… in which case, it is drawing outside the tree.
In both these examples, I am guessing these issues happen because the collision ended occurs at the first recognized instance in which the physics objects are no longer touching (as opposed to the instant right before they will stop touching, or the exact position where the collision ended). Feel free to correct me if I’m wrong. My question is how can I overcome these complicated issues? Is there a way I can get the notified a bit earlier than when I am already outside the physics body?
I feel like a " contains" function would be extremely useful. For example, if for all the complex physics bodies/shapes that I export from the PhysicsEditor, I could do something like myObj:contains(x,y). This would be so much easier than trying to coordinate collisions and touches, which might not time correctly. In Example 1, I could easily just call the function to test if I should stop the snowflake or not. In Example 2, I could call the function to test if I can paint or not.
I am using Build 2014.2511. I’d really appreciate some advice as these are some complicated issues that have recurred quite a bit while trying to implement more advanced functionalities. Feel free to let me know if you have any questions. I know it’s a lot to take in. Thank you very much!