Obi Official Forum
Unity Collider Position - Raycast Spherecast - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Unity Collider Position - Raycast Spherecast (/thread-2215.html)



Unity Collider Position - Raycast Spherecast - fishing-rod - 01-05-2020

Hi,

I want the player to be able to pick up a rod. I'm checking for pickable objects via spherecasting in front of the player. Unity collider, which are needed for raycasting, are not moving though when attached to a rod. How else could I detect a rod via casting?

greetings


RE: Unity Collider Position - Raycast Spherecast - josemendez - 01-05-2020

(01-05-2020, 02:31 PM)fishing-rod Wrote: Hi,

I want the player to be able to pick up a rod. I'm checking for pickable objects via spherecasting in front of the player. Unity collider, which are needed for raycasting, are not moving though when attached to a rod. How else could I detect a rod via casting?

greetings

Obi is not made using Unity's physics engine, so particles aren't part of Unity's physics engine (if they were, we would inherit all performance and stability problems of the built-in engine). Using raycasting/spherecasting won't detect them, as casting only works with the built-in Unity physics objects.

Particles use their own collision detection system, here's how you can get all to contacts in a frame and  detect Unity objects colliding against particles (trigger colliders work too):

http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.html


RE: Unity Collider Position - Raycast Spherecast - Kristaps - 01-05-2020

(01-05-2020, 02:41 PM)josemendez Wrote: Obi is not made using Unity's physics engine, so particles aren't part of Unity's physics engine (if they were, we would inherit all performance and stability problems of the built-in engine). Using raycasting/spherecasting won't detect them, as casting only works with the built-in Unity physics objects.

Particles use their own collision detection system, here's how you can get all to contacts in a frame and  detect Unity objects colliding against particles (trigger colliders work too):

http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.html

I just added Unity colliders to rope and job done!
Gran sonrisa


RE: Unity Collider Position - Raycast Spherecast - josemendez - 01-05-2020

(01-05-2020, 04:11 PM)Kristaps Wrote: I just added Unity colliders to rope and job done!
Gran sonrisa

Can be done, but kinda defeats the purpose of using particles Guiño.


RE: Unity Collider Position - Raycast Spherecast - Kristaps - 01-05-2020

(01-05-2020, 04:13 PM)josemendez Wrote: Can be done, but kinda defeats the purpose of using particles Guiño.

Noo, it's the perfect mix of both worlds!
Before Obi Ropes, my ropes were made from joints and line renderers ( did not look good and collisions were with gaps )
Now it's totally different and just need to adapt my needs Sonrisa



RE: Unity Collider Position - Raycast Spherecast - fishing-rod - 01-05-2020

(01-05-2020, 04:44 PM)Kristaps Wrote: Noo, it's the perfect mix of both worlds!
Before Obi Ropes, my ropes were made from joints and line renderers ( did not look good and collisions were with gaps )
Now it's totally different and just need to adapt my needs Sonrisa

@Kristaps How do you keep the colliders position and orientation in sync with the rope?


RE: Unity Collider Position - Raycast Spherecast - Kristaps - 01-05-2020

(01-05-2020, 05:53 PM)fishing-rod Wrote: @Kristaps How do you keep the colliders position and orientation in sync with the rope?

Made a little helper script:

unityCollider.position = obiActor.GetParticlePosition(obiActor.GetParticleRuntimeIndex(assignIndex));

assignIndex is the rope particle index
Guiño


RE: Unity Collider Position - Raycast Spherecast - fishing-rod - 02-05-2020

(01-05-2020, 06:34 PM)Kristaps Wrote: Made a little helper script:

unityCollider.position = obiActor.GetParticlePosition(obiActor.GetParticleRuntimeIndex(assignIndex));

assignIndex is the rope particle index
Guiño

Thank you very much! I guess unityCollider is a transform of a separated GameObject. I attached the collider directly to the rod and change the center. As particles return world space positions I transform them to local space first:


Code:
collider.center = collider.transform.InverseTransformPoint(rod.GetParticlePosition(rod.GetParticleRuntimeIndex(1)));