Custom touch control stops abruptly!
Hello!
I've made the type of controls i want my game to have almost perfectly by looking at other examples and combining what i already know!
using UnityEngine;
public class testmovement : MonoBehaviour
{
float initialxposition;
float initialyposition;
float initialxball;
float initialzball;
private Vector3 velocity = Vector3.zero;
private Vector3 EndLocation;
private bool FingerOnScreen = false;
private bool FingerMoving = false;
// Update is called once per frame
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
switch (touch.phase)
{
case TouchPhase.Began:
initialxposition = touch.position.x;
initialyposition = touch.position.y;
initialxball = transform.position.x;
initialzball = transform.position.z;
FingerOnScreen = true;
break;
case TouchPhase.Moved:
FingerMoving = true;
break;
case TouchPhase.Stationary:
FingerMoving = false;
break;
case TouchPhase.Ended:
FingerMoving = false;
FingerOnScreen = false;
break;
}
EndLocation = new Vector3((initialyposition - touch.position.y) / 5 + initialxball, transform.position.y, (touch.position.x - initialxposition) / 5 + initialzball);
transform.position = Vector3.SmoothDamp(transform.position, EndLocation, ref velocity, 5 * Time.deltaTime);
}
}
}
The only issue is that as soon as the user gets their finger off the screen, the object stops abruptly at the "EndLocation"
Im trying to make it so it keeps going for a little before "drag" puts it to a stop
ive tried adding an addforce that would add a certain amount of force in the same direction of the "EndLocation" but that didnt work out very good, so maybe im doing it wrong or theres a better way...
Thanks for any help fellas!
Your answer
Follow this Question
Related Questions
Figuring out what the acceleration will be before applying force to RigidBody2D 0 Answers
Falling Platform 1 Answer
Torque applies to one wheel, but inconsistently to the other wheel 0 Answers
Rocket Landing 1 Answer
RigidBody Controller Forces 0 Answers