Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Collider Effect On Obi Cloth Stops After A Few Seconds.
#3
(03-02-2020, 08:35 AM)josemendez Wrote: Hi,

Without taking a look at your scene setup and any custom script you may have, it's pretty much impossible to tell the cause of this. It could simply be that particles are getting projected outside the reach of the collider in the Z axis after colliding with it a few times (at least that's what it looks like: zones where the collider hasn't passed yet collide fine, but any parts that have already collided with it stop colliding).

You can't use Unity's built-in raycast methods to select particles, as they are not part of Unity's physics system. The particle dragger/picker are what you should use most of the time, all they do is cast a line segment from the mouse cursor position and then select the particle that's closest to it within a user-defined distance. They haven't changed at all since they were added back in 4.X, all you need to do is add them to an actor and drag over a solver to the picker's "Solver" slot. Could you tell me what issues are you having with them?

The code on the collider is pretty simple. At first I thought it was because the sphere just wasn't touching it because the mesh would deform down but I've tried to use it in 2d mode and I've also changed the collider prefab to an elongated capsule that is tall enough that it's always colliding. I assumed it was due to the lack of collision because I was getting some weird behaviors like the sphere ending up under the mesh even though the mesh is being pushed down and the sphere height is locked. I've confirmed it is running through the mesh and it still produces the same behavior as the sphere. 


Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PressureObjectManager : MonoBehaviour
{
    [SerializeField]
    bool m_IndependentDebugging;
    [SerializeField]
    Camera m_TargetCamera;
    [SerializeField]
    private GameObject m_PressureObject;

    public void Awake()
    {
        InputHandler.OnTouch += InputHandler_OnTouch;
    }

    private void InputHandler_OnTouch(InputHandler.TouchEventArgs args)
    {
        HandleTouchByPhase(args);
    }

    private void HandleTouchByPhase(InputHandler.TouchEventArgs args)
    {
        switch(args.Phase)
        {
            case TouchPhase.Began:
                {
                    BeginTouch(args.TouchIndex, args.TouchPosition, args.TouchPressure);
                    break;
                }
            case TouchPhase.Moved:
                {
                    MoveTouch(args.TouchIndex, args.TouchPosition, args.TouchPressure);
                    break;
                }
            case TouchPhase.Ended:
                {
                    EndTouch(args.TouchIndex);
                    break;
                }
            default:
                {
                    Debug.LogWarningFormat("Attempting To Handle Unregistered Touch Phase: {0}", args.Phase);
                    break;
                }
        }
    }

    Dictionary<int, GameObject> m_PressureObjects = new Dictionary<int, GameObject>();

    private void BeginTouch(int index, Vector3 position, double pressure)
    {
        if (m_IndependentDebugging)
            Debug.LogFormat
                ("Touch Began At Position ({0}) With A Pressure Of [{1}] At Index <{2}>", position, pressure, index);

        RaycastHit rayHit;
        if (Physics.Raycast(m_TargetCamera.ScreenPointToRay(position), out rayHit, 25.1f))
        {
            if (m_IndependentDebugging)
                Debug.LogFormat("Screen Touch Position Ray Hit Location: {0}", rayHit.point);

            Vector3 objPosition = rayHit.point;

            objPosition.y = -1;  //Account For Pressure

            if (!m_PressureObjects.ContainsKey(index))
            {
                m_PressureObjects.Add(index, Instantiate(m_PressureObject, objPosition, Quaternion.identity));
            }
        }
    }

    private void MoveTouch(int index, Vector3 position, double pressure)
    {
        if (m_IndependentDebugging)
            Debug.LogFormat
                ("Touch Moved To Position ({0}) With A Pressure Of [{1}] At Index <{2}>", position, pressure, index);

        RaycastHit rayHit;
        if (Physics.Raycast(m_TargetCamera.ScreenPointToRay(position), out rayHit, 25.1f))
        {
            if (m_IndependentDebugging)
                Debug.LogFormat("Screen Touch Position Ray Hit Location: {0}", rayHit.point);

            Vector3 objPosition = rayHit.point;

            objPosition.y = -1;  //Account For Pressure

            if (m_PressureObjects.ContainsKey(index))
            {
                m_PressureObjects[index].transform.position = objPosition;
            }
        }
    }

    private void EndTouch(int index)
    {
        if(m_PressureObjects.ContainsKey(index))
        {
            var o = m_PressureObjects[index];

            m_PressureObjects.Remove(index);

            Destroy(o);
        }
    }
}


As far a the particle dragger and picker, I've just been unable to find many resources on them. I was thinking it would be an alternative route to the colliders if they turn out to not be feasible. So I went looking for some demo code or something like that but the closest I could find to what I was looking for was a video on youtube that demonstrates the picker being used to simulate slime but It does not include the dragger and I think it's from a much earlier version. The dragger and picker work, but I've got some requirements like multi-touch that it the dragger does seem to support. Does it? I'd also like to be able to control what happens when I click and drag and the only way there seems to be to modify the behavior is through the constraints and parameters on the solver and the dragger component but I can't really produce the results I'm looking for with just that so I'm thinking I need to actually interact with the particles themselves. There's also some stuff I found on particle scripting but it doesn't really have demo code on how to select a particle. It more or less seems to iterate through an array of the particles in the solver. Ideally I would like to bridge this gap and be able to use the particle picker (I would guess?) in order to create my own drag, touch, and hold behaviors. I assume I would use the events in the particle picker, but I can't really seem to find documentation, sample code, or video on how to specifically use that component other than the attaching of it in the video. Also the particle dragger does not seem to require the hooking of an event from the editor side. Unless it subscribes to it via code? Having said all that, is it possible to support multi-touch with the particle picker? Is it possible to select multiple particles at a time like the blueprint editor aside from trying to determine what indices the particles around them would be at? If so, could you provide a link to maybe some sample code on the basics of it like unity has for the raycast or write me a quick snippet? I looked everywhere I could think, the only thing I've really found is the documentation generated by the .cs file and that just pretty much lists class members and functions, not so much how to use them.

This is the video: https://www.youtube.com/watch?v=yEYQyiQN...4&index=14

This is the particle scripting doc I mentioned: http://obi.virtualmethodstudio.com/tutor...icles.html

I think in this, you're saying that multi-touch is possible, but I'm not sure.
http://obi.virtualmethodstudio.com/forum...21#pid2121
Reply


Messages In This Thread
RE: Collider Effect On Obi Cloth Stops After A Few Seconds. - by GrimCaplan - 03-02-2020, 07:34 PM