- Home /
Touch MovementSpeed for Android/iOS
Hello!
I am facing problem with touch movement speed on iOS and Android devices in my 2D game. The problem is the speed movement of the 2D object in the scene.
I use the speed movement of the object 0.5f and then on the Android devices the object moves at the desired speed. If I use the same 0.5f speed on an iOS devices, the speed is too fast. In this case, for iOS, I have to reduce the speed to 0.1f so that the object moves in the same way as it moves on an Android devices. The question is, is it possible to set a universal speed for all devises so as not to change the speed value separately for different platforms before creating a build?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragFingerMove : MonoBehaviour
{
public float moveSpeed = 0.5f;
public GameObject Ship;
public float minY;
public float maxY;
public float minX;
public float maxX;
// Update is called once per frame
private void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
transform.Translate(touchDeltaPosition.x * moveSpeed * Time.deltaTime, touchDeltaPosition.y * moveSpeed * Time.deltaTime, 0);
}
if (Input.touchCount > 0 && Ship.GetComponent<ShipController>().isOver == false)
{
Ship.GetComponent<ShipController>().Fire(true);
}
else
{
Ship.GetComponent<ShipController>().Fire(false);
}
Vector2 curPos = transform.localPosition;
curPos.y = Mathf.Clamp(transform.localPosition.y,minY,maxY);
curPos.x = Mathf.Clamp(transform.localPosition.x,minX,maxX);
transform.localPosition = curPos;
}
}
Is the resolution of both phones exactly the same? You're using the touchPosition as the direction of your movement, but a vector of (1, 1, 1) on your Android, maybe, moves less than a vector of (1.1, 1.1, 1.1) on your larger IPhone. Either you could normalise the vector, or adjust it, depending on screen resolution. @$$anonymous$$sive
Your answer
Follow this Question
Related Questions
store the user touch input 0 Answers
different devices -> Different touch speed 3 Answers
Pressing multiple buttons in a single swipe [MOVEMENT] 2 Answers
How do I move an object with my finger?[C#] 1 Answer
Touch buttons for step movememt 3 Answers