Answer the question
In order to leave comments, you need to log in
Sine formula into swipe movement code. How to add?
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Threading;
using UnityEngine;
using UnityEngine.EventSystems;
public class Swipes : MonoBehaviour, IDragHandler, IBeginDragHandler
{
public float acceleration;
public Rigidbody rb;
void Start()
{
}
public void OnBeginDrag(PointerEventData eventData)
{
if (Mathf.Abs(eventData.delta.x) > Mathf.Abs(eventData.delta.y))
{
if (eventData.delta.x > 0) Debug.Log("Right");
else Debug.Log("Left");
rb.AddForce(new Vector3(eventData.delta.x, 0, 0) * acceleration);
}
else
{
if (eventData.delta.y > 0) Debug.Log("Up");
else Debug.Log("Down");
rb.AddForce(new Vector3(0, 0, eventData.delta.y) * acceleration);
}
}
public void OnDrag(PointerEventData eventData)
{
}
}
"If you need to get the Swipe angle directly, you can use the formula , which allows you to calculate the sine of the angle of a right triangle from the ratio of the opposite and adjacent sides"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question