Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unity Collider Position - Raycast Spherecast
#1
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
Reply
#2
(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
Reply
#3
(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
The developer of Area 86 
https://simdevs.com
Reply
#4
(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.
Reply
#5
(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
The developer of Area 86 
https://simdevs.com
Reply
#6
(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?
Reply
#7
(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
The developer of Area 86 
https://simdevs.com
Reply
#8
(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)));
Reply