0 votes

Hi all,

I think i am missing something while working with input() and _inputevent() callbacks.
I want to pickup a RigidBody using touch / mouse left button pressed but only release it when the touch is "unpressed" (even if this event happens NOT on the rigidBody).

I have one script attached to my RigidBody, noting that main scene contains many instance of this rigidbody. (I removed the debugging prints below).

var mCurLiftedBody = null

PickUp: (In order to catch the "pressed" event on this rigidbody)

func _input_event(camera, event, pos, normal, shape):
if (event is InputEventMouseButton and event.is_pressed() == true):
            self.get_node("Mesh").set_surface_material(0, null)
            self.set_mode(  MODE_STATIC ) 
            #mCurLiftedBody = self
            mCurLiftedBody = get_node(".")

Release (Anywhere on the screen)

func _input(ev):
    #if(ev is InputEventScreenTouch && ev.pressed == false):
    if(ev is InputEventMouseButton && ev.pressed == false):

    if( mCurLiftedBody != null):
        mCurLiftedBody.set_mode( MODE_RIGID )
        mCurLiftedBody.get_node("Mesh").set_surface_material(0, null)
        mCurLiftedBody = null

My problem is, not that it is not working, but that it is not Always working...

Sometimes the prints are working correctly (picked up / released) sometimes not.
Sometimes the prints are working correctly but the mesh isn't being nullified ...

I checked this and this too but couldn't find the answer.

The main scene contains other rigid and static bodies and collision occurs but I don't think the problem is from there...

in Engine by (858 points)
edited by

1 Answer

+1 vote
Best answer

Solved it myself, can sleep parameter was the issue...

by (858 points)
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 Frequently asked questions and 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 [email protected] with your username.