Obi Official Forum

Full Version: Unity Collider Position - Raycast Spherecast
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
(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/tutor...sions.html
(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/tutor...sions.html

I just added Unity colliders to rope and job done!
Gran sonrisa
(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.
(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
(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?
(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
(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)));