Question by
mafalate · May 07, 2017 at 08:14 AM ·
scripting problemiosswipethrow
Swiping is not throwing my object
I used over 4 different scripting methods to throw my object but for some reason non of them seem to throw in game.
Here is my current script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddForce : MonoBehaviour
{
private Touch initialTouch = new Touch();
private float distance = 0;
private bool hasSwiped = false;
private void FixedUpdate()
{
foreach (Touch t in Input.touches)
{
if (t.phase == TouchPhase.Began)
{
initialTouch = t;
}
else if (t.phase == TouchPhase.Moved && !hasSwiped)
{
float deltaX = initialTouch.position.x - t.position.x;
float deltaY = initialTouch.position.y - t.position.y;
distance = Mathf.Sqrt((deltaX * deltaX) * (deltaY * deltaY));
bool threwWeapon = Mathf.Abs(deltaX) > Mathf.Abs(deltaY);
if (distance > 100f)
{
if (threwWeapon && deltaY <=0.0001)
{
{
GetComponent<Rigidbody>().velocity = new Vector3(GetComponent<Rigidbody>().velocity.x, 0, GetComponent<Rigidbody>().velocity.z);
GetComponent<Rigidbody>().AddForce(new Vector3(0, 100f, 0));
}
}
}
hasSwiped = true;
}
else if (t.phase == TouchPhase.Ended)
{
initialTouch = new Touch();
hasSwiped = false;
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612121446im_/https://answers.unity.com/themes/thub/images/avi.jpg)