- Home /
Question by
QuestionZ · Jan 02, 2019 at 01:11 AM ·
resolutiondeltadelta position
Drag speed different on resolutions
Hello, I am working 3d drag game. Character goes slow/fast x axis on different mobile phone resolutions.
For example: it goes really smooth & fast in 1920x1080 but its not like in 1080x720
As far as i know deltaposition are in pixels. Thats why it goes different speed in different resolutions. But I couldnt figured out how can i fix this.
Code;
if (Input.touchCount == 1)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = touch.deltaPosition;
TranslateBall(touchDeltaPosition, 0.3f);
}
public void TranslateBall(Vector2 position, float translationSpeed)
{
transform.Translate(position.x * translationSpeed * Time.deltaTime, 0f, 0f);
}
Comment
Answer by Snipe76 · Jan 02, 2019 at 03:53 PM
Here are few solutions that I could think of:
Everything that is physics based should be used and calculated in FixedUpdate() function instead of Update().
Try to calculate your own deltaPosition instead of using the built-in one:
currentPosition.x = Input.GetTouch(0).position.x - pastPosition.x; currentPosition.y = Input.GetTouch(0).position.y - pastPosition.y; pastPosition = Input.GetTouch(0).position;
Try using touch world space instead of deltaPosition.