0 votes

I am trying to create an inertial vertical scrolling effect for an android app (the kind you see when scrolling through a list).

To do this, I am using a RigidBody2D node to listen for a SCREEN_DRAG input event then to set it's linear velocity on the y-axis to the speed of the screen drag event. I will then attach any items I need to scroll to the RigidBody. The RigidBody2D has a Gravity Scale of 0 and a linear damping overide set to slow it down.

extends RigidBody2D

func _ready():  
  set_process_input(true)

func _input(event):
  if event.type == InputEvent.SCREEN_DRAG:          
        set_linear_velocity(Vector2(0,event.speed_y))           

Everything works exactly as planned when I run the project in the onboard project player, using the mouse set to emulate touchscreen in project settings. However, when I export to android the RigidBody2D won't move in response to a drag event. I can see in logcat that an input event is being detected.

If I try a simpler non-inertial approach, for example, just moving the RigidBody2D node in response to a drag event with:

move_local_y(event.relative_y)

then everything works fine in the exported android version, but I'm after an inertial effect and I thought using the physics body's velocity or impulse functions would be the best way to achieve this.

I have put an example project here

I would welcome any advice, either how to fix the issue or how to achieve an inertial scrolling effect in a different way.

in Engine by (99 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.