Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi Collision Detection
#1
Hello Obi Team,

I am working on a mobile game project using Obi Rope 5.6. My goal in the game is:

  • There is a frame with joints attached on it.
  • There is a rope source in the left bottom of the frame.
  • I will be whipping the rope around these joints.
  • It's actually very similar to the WrapTheRope sample in the project. But input control in this project is by dragging not by holding W, A, S, D buttons on the keyboard. And another difference is I am working on a 3D environment.

[Image: Screen-Shot-2020-12-21-at-4-20-38-PM.png]

I am changing the length of the rope by checking the distance between the source joint and the rope tip. To be able to calculate the length correctly, I need the information of last collided joint. Because if I drag the rope to the joint on the very top first, then drag it to joints in the bottom, its length should be:


Quote: (distance from source to joint on the top + distance from joint on the top to the joint on the bottom)



For this approach, I need to know when the rope enters/exits colliding with the joints. I also need to roll the rope back to the last collided joint when player stops dragging. But it seems there is no method for collision exit. Is there any other way to understand that the rope started/ended colliding with the specific objects in order? If not, what would be the best solution for my problem?

Thank you in advance. I love and appreciate your work!

Regards
Reply
#2
Hi there,

Obi collision events just give you a list of all contacts during the current frame. If you store both this frame's contacts and the current frame's contacts, getting enter/exit/stay events is trivial:

- Contacts appearing in the current frame but not in the previous one are new, hence a enter event.
- Contacts appearing in the previous frame but not in the current have disappeared, hence a exit event.
- Contacts appearing in both frames continue to exist, hence a stay event.

Checking this can be done in linear time (O(n + m),where n and m are the amount of contacts in previous and current frame) using a zipper-like algorithm. This is exactly what the sample ObiContactEventDispatcher component does. You can find it at Obi/Scripts/Common/Utils/. This component will trigger an event for each enter/stay/exit, that you can subscribe to and perform any custom logic.

cheers,
Reply
#3
Hi Jose,

Thank you for your quick reply. I have just checked my project and I couldn't see any file or component named/containing ObiContactEventDispatcher. I am using Obi Rope version 5.6 and my Unity version is 2019.3.7f1.

Thank you in advance.

Regards
Reply
#4
(21-12-2020, 03:10 PM)meryemekinci Wrote: Hi Jose,

Thank you for your quick reply. I have just checked my project and I couldn't see any file or component named/containing ObiContactEventDispatcher. I am using Obi Rope version 5.6 and my Unity version is 2019.3.7f1.

Thank you in advance.

Regards

Hi,

This component was added in 5.6.1. The latest version is 5.6.2, I'd recommend updating, if only for the heap of bugfixes included. If not possible for some reason, you can find the component attached to this post.


Attached Files
.cs   ObiContactEventDispatcher.cs (Size: 5.32 KB / Downloads: 8)
Reply
#5
Corazón 
I will update it to 5.6.2 right away, and will let you know. Thank you so much!
Reply
#6
Using enter/exit callbacks solved my problem with detection collisions. Thank you so much, Jose.

I am not sure if I should open a new thread for another problem, but I will ask it from here first. Then I can remove it if needed.

As I said before, I move the rope by dragging a game object (let's call it rope tip) that my rope's control point has its position as target. Whenever there is a dragging input, I change the rope tip's position. The problem is when I stop dragging the object, the rope pulls the tip back for a while. First I thought it was because there might be some distance between particles and they were trying to cover the distance by getting close to eachother. But when I check their alignment with Particle Renderer, they are already up close to eachother. Probably I am missing some constraint or defining some wrong. I need the rope to not pull back the rope tip back.

Thank you in advance.

Regards
Reply
#7
(23-12-2020, 12:20 PM)meryemekinci Wrote: Using enter/exit callbacks solved my problem with detection collisions. Thank you so much, Jose.

I am not sure if I should open a new thread for another problem, but I will ask it from here first. Then I can remove it if needed.

As I said before, I move the rope by dragging a game object (let's call it rope tip) that my rope's control point has its position as target. Whenever there is a dragging input, I change the rope tip's position. The problem is when I stop dragging the object, the rope pulls the tip back for a while. First I thought it was because there might be some distance between particles and they were trying to cover the distance by getting close to eachother. But when I check their alignment with Particle Renderer, they are already up close to eachother. Probably I am missing some constraint or defining some wrong. I need the rope to not pull back the rope tip back.

Thank you in advance.

Regards

Is the tip a rigidbody? if so, the rope will exert forces on it. How much force, depends on the mass ratio between the rope and the "tip". Depending on the constraints used by your rope (bend, distance) the direction of this force will change. You can play with the mass of both the tip and the rope to control how they move relative to each other.

It could also be that the tip is colliding with the rope particles, as described in the last bit of this page:
http://obi.virtualmethodstudio.com/tutor...aints.html

The exact cause is difficult to tell without looking at your setup in more detail, though.
Reply
#8
Bombilla 
Yes, it was definitely because of the rigidbody on the tip. I was trying to move the rope by using force similar to WrapTheRope sample at the beginning of the project. Definitely my fault. Thank you again for your time and quick responses.
Reply
#9
I have different objects with ObiCollider component on them. I need to understand if these objects collide with each other, not with the rope. Is this possible?

Thanks in advance.

Regards
Reply
#10
(24-12-2020, 01:42 PM)meryemekinci Wrote: I have different objects with ObiCollider component on them. I need to understand if these objects collide with each other, not with the rope. Is this possible?

Thanks in advance.

Regards

Yes, but this is not Obi's responsibility. Obi only simulates particles.

Collision detection between regular colliders is done by Unity. See:
https://docs.unity3d.com/ScriptReference...Enter.html
Reply