Federico-Ciuffardi / GodotTouchInputManager

Asset that improves touch input support (includes new gestures) in the Godot game engine. It also translates mouse input to touch input.
MIT License
526 stars 35 forks source link

event.position in InputEventScreenPinch not centered during first few events #5

Closed therioko closed 4 years ago

therioko commented 4 years ago

Nice work! Here's a minor bug I ran into.

Environment

How to reproduce

Run the following code and pinch the screen.

    if event is InputEventScreenPinch:
        print(event.position)

Expected behavior

event.position is always centered

Encountered behavior

event.position is not centered but contains the last value of InputEventSingleScreenDrag for the first few events when starting to pinch the screen.

Federico-Ciuffardi commented 4 years ago

Hi!

What I think is going on is that as a pinch event is only triggered when fingers are moved all inward the center or all outward the center, when you notice that the InputEventScreenPinch is not centered is because a InputEventMultiScreenDrag is triggering instead as you somehow stop moving all the fingers outward or inward the center.

Please check out and let me know. Please set the debug attribute to true in InputManager.gd so all InputEvents get print as they are triggered.

therioko commented 4 years ago

So I'm running this on a super basic setup: I've loaded InputManager in a 3D scene and I'm using a 3D camera. I've turned debug true, deployed it to iOS and recorded the following output by triggering a InputEventSingleScreenDrag event and then going into InputEventScreenPinch. Take a look at the position output. The first two InputEventScreenPinch events still have a uncentered position relative to the previous InputEventSingleScreenDrag. The third one, then, is centered.

2020-03-29 10:58:56.759579+0200 Demo[21195:9338053] InputEventSingleScreenDrag : position=(808, 763), relative=(0, 4), speed=(-39.384853, 309.520477)
InputEventSingleScreenDrag : position=(808, 763), relative=(0, 4), speed=(-39.384853, 309.520477)
2020-03-29 10:58:56.780784+0200 Demo[21195:9338053] InputEventSingleScreenDrag : position=(808, 768), relative=(0, 5), speed=(-39.384853, 309.520477)
InputEventSingleScreenDrag : position=(808, 768), relative=(0, 5), speed=(-39.384853, 309.520477)
2020-03-29 10:58:56.799385+0200 Demo[21195:9338053] InputEventSingleScreenDrag : position=(808, 774), relative=(0, 6), speed=(-39.384853, 309.520477)
InputEventSingleScreenDrag : position=(808, 774), relative=(0, 6), speed=(-39.384853, 309.520477)
2020-03-29 10:58:56.800340+0200 Demo[21195:9338053] InputEventScreenPinch : position=(808, 777), relative=3, distance =0, speed=312.016174
InputEventScreenPinch : position=(808, 777), relative=3, distance =0, speed=312.016174
2020-03-29 10:58:56.823077+0200 Demo[21195:9338053] InputEventScreenPinch : position=(807, 786), relative=9.055386, distance =0, speed=312.016174
InputEventScreenPinch : position=(807, 786), relative=9.055386, distance =0, speed=312.016174
2020-03-29 10:58:56.823560+0200 Demo[21195:9338053] InputEventScreenPinch : position=(564, 1313), relative=-4.294067, distance =1160.651489, speed=156.008087
InputEventScreenPinch : position=(564, 1313), relative=-4.294067, distance =1160.651489, speed=156.008087
2020-03-29 10:58:56.843670+0200 Demo[21195:9338053] InputEventScreenPinch : position=(564, 1316), relative=-2.720215, distance =1155.205566, speed=156.008087
Federico-Ciuffardi commented 4 years ago

I think this could fix it: https://github.com/Federico-Ciuffardi/Godot-Touch-Input-Manager/archive/ugfix.zip

Can you try it and tell me if the bug is gone?