Problem with touch and moving

Hi guys :slight_smile:

I want to move my player in 2D (it’s a shoot em up) the exact amount of movement that my finger does. I’ve been looking at this script:

// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
        
// Move object across XY plane
transform.Translate (-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);

The problem it’s the speed value. Depends of that, the player moves more than the finger or less. I don’t want to try every value to get the correct one. Besides I think that it has something to do with screen resolution.

So, anyone knows how to get the correct speed value?

Thanks!

what is speed?
the speed of your finger drag?
Are you just setting the position of object at position of finger?

I think what he’s trying to get at is that his player isn’t following his finger position. Which would be because the finger position is in screenspace, and you are moving your character in worldspace.

You could use a raycast to an invisible collider on the 2d plane of your game. From there you could get a world position of your touches to calculate the speed.

Default117 is right, player is going faster or slower (depends of speed value, it’s a constant value that I put) than the finger, that’s the problem.

Uncade has a point, I will try, thanks :slight_smile:

Works like a charm! But only if I don’t multiply for deltaTime