The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

I'm trying to have my character equip a rock, which visually it does but it actually is on the on the ground. When i try to throw it, it starts form the ground not the hand...i searched about this and people said you have to use _integrate_forces() to move a rigidbody but i don't know how to make it work.
Anyone who has ideas on how to position my RigidBody2Drock on my characters Position2Dhand...please help.

in Engine by (47 points)

This doesn't really answer your question, but why don't you just delete the RigidBody from the ground and then add a KinematicBody2D version of the rock in the character's hands? When you want to throw the rock, you can either swap it with the RigidBody version again or use move_and_slide(). So the whole sequence is broken down into 3 parts:

1) Pick up the rock. The rock disappears from the ground and a KinematicBody2D version of the rock appears in your character's hands,

2) When about to throw the rock, delete the KinematicBody2D and spawn a RigidBody rock in its place.

3) Apply forces to the RigidBody rock so that it moves forward or whatever.

How do you spawn things in one's place?

1 Answer

+5 votes
Best answer

You need to remove the rigid body from physics processing while it's being held. When picked up, change its mode to MODE_STATIC.

When you want to drop it, change the mode back to MODE_RIGID. Note that when you do this it will be in the sleeping state, so you must apply some force or impulse.

You can see an example of this using mouse drag and drop here:

The VR tutorial in the docs also does this to handle picking up/throwing objects:

by (22,191 points)
selected by

Okay...i can now pick the ball and throw it character is he is controlled by the rock..whenever i run his hands swing back and forth i.e the stone,with this the character himself goes back and forth...any solutions?
P.S i think it has something to do with the global_transform.origin
And thanks for the help.

You're probably colliding with it. Set your collision layers/masks so that the player and rock don't collide or set collision_layer = 0 on pickup (and remember to set it back when you drop).

Thanks man...It worked.

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.