Obi Official Forum
How to make the Start/End Prefab able to be Raycasted? - Printable Version

+- Obi Official Forum (http://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (http://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (http://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: How to make the Start/End Prefab able to be Raycasted? (/thread-217.html)

Pages: 1 2 3


How to make the Start/End Prefab able to be Raycasted? - Rexima - 30-10-2017

I want to be able to grab my Rope on the End or Start, and i thought to raycast the end/start of it, so the player can grab it.
How can this be done?


RE: How to make the Start/End Prefab able to be Raycasted? - josemendez - 30-10-2017

(30-10-2017, 09:32 AM)Rexima Wrote: I want to be able to grab my Rope on the End or Start, and i thought to raycast the end/start of it, so the player can grab it.
How can this be done?

Hi there,

Raycasting is the wrong approach (in fact, what do you want to raycast exactly? there are no colliders in a rope, and you cannot trivially raycast against a deformable mesh).

You should use handles, and a proximity test to see if your grappling point (e.g. player hand) is near the rope end/start. If it is, then create a handle. Alternatively you can just fix the first/last particles in the rope and directly set their position to whatever you need them to be. See:
http://obi.virtualmethodstudio.com/tutorials/attachments.html
http://obi.virtualmethodstudio.com/tutorials/scriptingparticles.html

Edit: If you're doing this for VR, there are a few threads on the subject:
http://obi.virtualmethodstudio.com/forum/showthread.php?tid=197&highlight=niZmo
http://obi.virtualmethodstudio.com/forum/showthread.php?tid=82&highlight=niZmo


RE: How to make the Start/End Prefab able to be Raycasted? - Rexima - 30-10-2017

I have an First Person Character Controller, if i make any proximity checks with the character, than it wont work like expected.
My Player need to aim at one End, the End should be Outlined and than if he press an button, the end is in his "hands".

I hope you know what i mean. The player needs to take the rope and connect it with an Entity, so i need to let him grab one End.

Edit: I was lil bit stupid... I just attached my Pickup and Outline Script on the Start/End prefabs and now its working. (So now im able to create an handle at the right position) But to grab the Rope i need to create an ObiParticleHandle, right?
Is there any good sample / tutorial, how to grab it?
I managed to move the handler, but the rope is still on the ground. Do i need to pin the rope end to the handle?


RE: How to make the Start/End Prefab able to be Raycasted? - josemendez - 30-10-2017

(30-10-2017, 03:37 PM)Rexima Wrote: I have an First Person Character Controller, if i make any proximity checks with the character, than it wont work like expected.
My Player need to aim at one End, the End should be Outlined and than if he press an button, the end is in his "hands".

I hope you know what i mean. The player needs to take the rope and connect it with an Entity, so i need to let him grab one End.

Edit: I was lil bit stupid... I just attached my Pickup and Outline Script on the Start/End prefabs and now its working. (So now im able to create an handle at the right position) But to grab the Rope i need to create an ObiParticleHandle, right?
Is there any good sample / tutorial, how to grab it?
I managed to move the handler, but the rope is still on the ground. Do i need to pin the rope end to the handle?

Yes, you need to create a ObiParticleHandle. All of this is in the manual, scripting section. You can either create a handle:

Code:
// Create the handle:
GameObject c = new GameObject("Obi Handle");
ObiParticleHandle handle = c.AddComponent<ObiParticleHandle>();
handle.Actor = actor;

c.transform.position = /*position the handle here*/;

// Add the selected particle(s) to the handle:
handle.AddParticle(i,/*position of the particle in world space*/,actor.invMasses[i]);


Or use the low-level API to fix the particles in place and move them around yourself. Handles are just a fancy way to move particles around using a transform, but in some cases (like this one) you can just move the particles directly yourself. The sample code in the manual (under "setting particle properties") does exactly this:
http://obi.virtualmethodstudio.com/tutorials/scriptingparticles.html


RE: How to make the Start/End Prefab able to be Raycasted? - Rexima - 30-10-2017

I made what you said and i can hold my rope now, but i when i pick it up, i have only the end and start prefab in my hands.
The rope is away  Ángel

Code:
m_handleGO = new GameObject("Obi Handle");
    m_handle = m_handleGO.AddComponent<ObiParticleHandle>();
   m_handle.Actor = m_rope;

   void FixedUpdate()
   {
       if (m_rope == null)
           return;

       if (m_handleGO == null)
           return;

       if (m_handle == null)
           return;  


       m_handleGO.transform.position = Vector3.Lerp(transform.position, PlayerCamera.Instance.transform.position + PlayerCamera.Instance.transform.forward * .8f, Time.deltaTime * 20);

       // Add the selected particle(s) to the handle:
       for (int i = 0; i < m_rope.invMasses.Length; ++i)
       {
           m_handle.AddParticle(i, m_handleGO.transform.position, m_rope.invMasses[i]);
       }
   }
How do i set the position of each particle? Sorry for this questions, but i bought this asset a day ago and i can't understand how to use it  Sonrojado


RE: How to make the Start/End Prefab able to be Raycasted? - josemendez - 31-10-2017

(30-10-2017, 09:05 PM)Rexima Wrote: I made what you said and i can hold my rope now, but i when i pick it up, i have only the end and start prefab in my hands.
The rope is away  Ángel



Code:
   m_handleGO = new GameObject("Obi Handle");
   m_handle = m_handleGO.AddComponent<ObiParticleHandle>();
   m_handle.Actor = m_rope;

   void FixedUpdate()
   {
       if (m_rope == null)
           return;

       if (m_handleGO == null)
           return;

       if (m_handle == null)
           return;  


       m_handleGO.transform.position = Vector3.Lerp(transform.position, PlayerCamera.Instance.transform.position + PlayerCamera.Instance.transform.forward * .8f, Time.deltaTime * 20);

       // Add the selected particle(s) to the handle:
       for (int i = 0; i < m_rope.invMasses.Length; ++i)
       {
           m_handle.AddParticle(i, m_handleGO.transform.position, m_rope.invMasses[i]);
       }
   }
How do i set the position of each particle? Sorry for this questions, but i bought this asset a day ago and i can't understand how to use it  Sonrojado

Hi,

FixedUpdate runs once (or zero, or multiple times) per frame, so your code is creating a handle and then adding the same particle to the handle every frame, setting its position to be whatever position the particle has that frame. This is wrong. 

Particles should only be added once, with the position they should have relative to the handle. The handle will take care of positioning the particle so that it keeps the same position relative to its frame, no need to manually set particle positions if you're using handles.


RE: How to make the Start/End Prefab able to be Raycasted? - Rexima - 01-11-2017

Thank you very much for your help, but how do i know the new position of each particle?

I need to add all Particles once, and than i need to move the handler where my "hand" is.
But the problem is, how to add all Particles, how do i know the new position of them?

This is in my Init void:
Code:
m_handleGO = new GameObject("Obi Handle");
            m_handle = m_handleGO.AddComponent<ObiParticleHandle>();
            m_handle.Actor = m_rope;


            // Add the selected particle(s) to the handle:
            for (int i = 0; i < m_rope.invMasses.Length; ++i)
            {
                m_handle.AddParticle(i, m_rope.GetParticlePosition(i) / m_rope.invMasses[i], m_rope.invMasses[i]);
            }

And this in FixedUpdate to move the Handler:
Code:
m_handleGO.transform.position = Vector3.Lerp(transform.position, PlayerCamera.Instance.transform.position + PlayerCamera.Instance.transform.forward * .8f, Time.deltaTime * 20);

In the Attachment you can see, how it looks, when i pick the rope up.


RE: How to make the Start/End Prefab able to be Raycasted? - josemendez - 01-11-2017

(01-11-2017, 11:23 AM)Rexima Wrote: Thank you very much for your help, but how do i know the new position of each particle?

I need to add all Particles once, and than i need to move the handler where my "hand" is.
But the problem is, how to add all Particles, how do i know the new position of them?

This is in my Init void:


Code:
m_handleGO = new GameObject("Obi Handle");
           m_handle = m_handleGO.AddComponent<ObiParticleHandle>();
           m_handle.Actor = m_rope;


           // Add the selected particle(s) to the handle:
           for (int i = 0; i < m_rope.invMasses.Length; ++i)
           {
               m_handle.AddParticle(i, m_rope.GetParticlePosition(i) / m_rope.invMasses[i], m_rope.invMasses[i]);
           }

And this in FixedUpdate to move the Handler:


Code:
m_handleGO.transform.position = Vector3.Lerp(transform.position, PlayerCamera.Instance.transform.position + PlayerCamera.Instance.transform.forward * .8f, Time.deltaTime * 20);

In the Attachment you can see, how it looks, when i pick the rope up.

Hi!

Why do you divide the position of each particle by its mass when initializing the handle? It doesn't make sense in this context... and will yield completely incorrect results for your purposes. Also, you're adding ALL particles in the rope to the handle. I was under the impression that you only wanted the first/last particles to be handled, and let the rest of the rope be simulated.

The initial position of each particle in the handle must be the one you wish them to be in relation to the handle. For instance, if you wish the particle to be exactly on top of the handle, then you must pass the handle's position. Passing the current particle position as you do now, will NOT make the particle "teleport" to the handle position at the start, it will make sure the particle keeps that position relative to the handle.

 From then on, the handle itself will make sure that the particles keep the same position in its local space. You no longer need to do anything once the handle has been set up. Just moving the handle around will be enough.


RE: How to make the Start/End Prefab able to be Raycasted? - Rexima - 01-11-2017

Sorry for real, i try to understand how it works. Thank you very much, you are so patient.
I will try to explain how my concept is now made.

The Start and End Prefab have 2 scripts attached.
One for Outlining and one which handles, what should happen, when my player is hitting it.
The two Prefabs have an Collider attached and are on the Layer "Pickable"

So, when my player aim at the start or end object, the object get outlined and i can press an button to interact with this object.
When i press an button, it will call an function on the object.

This works so far, i can interact with the created end / start prefab.

So, the script on the prefabs, looks like this: https://hastebin.com/gohosewoyi.cs

With this code, im moving the handle but not the rope end.

Edit: I just added this line "m_handle.AddParticle(0, transform.position, 1f);" (https://hastebin.com/ebevojocak.cs) and now i grab the first particle, i think. I need to figure out, how to grab the right particle, than its working Sonrisa

Edit 2: Ok, i think its working like i said now. Thank you very much.


RE: How to make the Start/End Prefab able to be Raycasted? - josemendez - 01-11-2017

Glad you got it working! If you need further help don't hesitate to ask. Sonrisa