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);
}