A
A
Artem Kravchenko2020-09-06 15:05:03
Unity
Artem Kravchenko, 2020-09-06 15:05:03

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)
    {

    }
}


Hello! The code that is in the question is needed in order for the object to move along the swipe. It only moves forward/backward, left/right. Where I got this code from, it says:
"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"

What is this formula, how should it look in the code, and how should it be used at all? Help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question