22-01-2021, 09:27 AM
(This post was last modified: 22-01-2021, 09:29 AM by josemendez.)
(21-01-2021, 04:17 PM)meryemekinci Wrote: Hi Jose,
I am using the OnEnter, OnExit methods to understand collisions in my project right now. But I am having another challenge. (You can see a video of gameplay from the game in the previous replies (#13), if it's not visible, I can send another one.)
The issue is that when I roll the rope around two joints once and I try to roll around already-contacting joint again, OnEnter is not going to be called. But since the length of the rope is expected to be changed according to number of contacting joints, this problem makes my calculation not work properly.
How can I know that the rope contacts with an already-contacting joint?
Thank you in advance.
Hi there,
You can't use the OnEnter event for this, because it will only be triggered the first time a collider touches the rope. Enter/Exit/Stay behave the same way as Unity's contact events.
You will need to use the raw collision callbacks (http://obi.virtualmethodstudio.com/tutor...sions.html). Keep track of a list of all colliders in contact with the rope, in chronological order. When you detect a new collision with a collider already in the list (that is, same collider index, but different particle index), check if it's the last one or not. If it's the last one, the rope is still wrapping around the same collider. If it's not, it means the rope is wrapped around a different collider, but has returned to wrap around a collider it was already in contact with. To clarify:
Case 1: current collider list is A, B, C, D, a new contact with collider D has been detected. The rope is still wrapping around D. Nothing to do.
Case 2: current collider list is A, B, C, D, a new contact with collider B has been detected. The rope is wrapping around B a second time, add B to the list (so it becomes A, B, C, D, B).
This is the first idea that comes to mind, there might be other ways to do it. hope this helps. cheers!