+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.

asked Aug 13, 2019 in Engine by Yoseph (41 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

+2 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: http://kidscancode.org/godot_recipes/physics/rigidbody_drag_drop/

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

answered Aug 13, 2019 by kidscancode (17,180 points)
selected Aug 13, 2019 by Yoseph

Okay...i can now pick the ball and throw it but....my character is glitching...like 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 How to use this Q&A? before posting your first questions.