Get delta direction of world ray touch

Hi guys!
I’m in the process of making a game where the player can swipe different objects around, based on the direction and speed of the swipe, as well as the object it’s hitting.

My current problem however, is that it’s incredibly inconsistent, and acts very strangely.

So what I’m looking for:

Send Speed of the highest value of X/Y Delta position of the raycast to the object that it’s touching.

But it just doesn’t seem to work? I’d highly appreciate if anyone had the time to go over the code, and see if there’s any obvious flaws in the approach/code.

Thank you!

void FixedUpdate ()
{
    if (Input.touchCount > 0)
    {
       
        Ray ray = Camera.main.ScreenPointToRay (Input.touches [0].position);
        RaycastHit hitInfo;
       
       
        if (Physics.Raycast (ray, out hitInfo))
        {
            Vector3 worldSpaceHitPoint = hitInfo.point;
           
            deltaYtouch = (lastYposTouch - hitInfo.point.y);
            lastYposTouch = hitInfo.point.y;
           
            deltaXtouch = (lastXposTouch - hitInfo.point.x);
            lastXposTouch = hitInfo.point.x;
            Debug.Log (deltaXtouch + "    " + deltaYtouch);
            if(hitInfo.transform.name == "MidRight")
            {
                if(hitInfo.transform.parent.name == "Left")
                {
                    if(moveThreshold < Mathf.Abs(deltaYtouch) || moveThreshold < Mathf.Abs(deltaXtouch) )
                    {
                        if(deltaYtouch > deltaXtouch)
                        {
                            StartCoroutine("SendDelayDirection",(deltaYtouch*speedAdjust));
                            StartCoroutine("SendDelaySide","RotateFrontSemi");
                        }
                        if(deltaYtouch < deltaXtouch)
                        {
                            StartCoroutine("SendDelayDirection",(deltaXtouch*speedAdjust));
                            StartCoroutine("SendDelaySide","RotateHorizontalCenter");
                        }
                    }
                }
            }
        }
       
    }
    else
    {
        deltaYtouch = 0;
        deltaXtouch = 0;
    }
   
}   

IEnumerator SendDelayDirection(float directionHolder)
{
    if(sendingDirection == false)
    {
        sendingDirection = true;
        yield return new WaitForSeconds(0.2f);
       
        SendMessage("SetDirection", directionHolder);
        sendingDirection = false;
    }
}

IEnumerator SendDelaySide(string activeSide)
{
    yield return new WaitForSeconds(0.2f);
   
    SendMessage("StartRotation",activeSide);
   
}

Anyone?

Not entirely sure what you are going for here. Can you explain better?

I want to send a message to another script, that is based around the speed of the swipe on an object. When I press, it casts a ray, and then it tries (but fails) to check the speed, and send the right message depending on whether the swipe is going upwards (ray.position.y rapid increase/decrease) & sidewards (ray.position.x rapid increase/decrease) - but it’s being consistent in the way it’s checking the delta position of the ray (and check what axis is experiencing the biggest changes).