# Pull Object Toward Character?

Hi! In my game I need to pick up a physics object that is laying among other physics objects… I’m trying to figure out if there’s a force formula for pulling objects closer toward the character so that it can pick it up?

Thanks!

You just have to compute the vector joining your object position to the character.

Something like : character.getWorldTranslation().subtract(object.getWorldTranslation()).normalize().mult(strength).
Not sure about the real syntax, but it may not be far from this.

3 Likes
@udoobu said: Hi! In my game I need to pick up a physics object that is laying among other physics objects... I'm trying to figure out if there's a force formula for pulling objects closer toward the character so that it can pick it up?

Thanks!

@yang71 said: You just have to compute the vector joining your object position to the character.

Something like : character.getWorldTranslation().subtract(object.getWorldTranslation()).normalize().mult(strength).
Not sure about the real syntax, but it may not be far from this.

Once you have that vector you can set the desired object’s gravity as towards your character. You probably want to normalize the vector from the object to your character before you set the gravity though, because otherwise you might have it go towards you way too fast.

1 Like

Thanks for your feedback, guys! I’m working to implement your suggestions. I may have additional questions - I’ll post them here. I really appreciate it!

THIS WORKS! Thank you both for your input, I couldn’t have done this without it.

This allowed me to create a “force pull” type of action to pull the object to my character’s “hand” in order to carry the object away. Once the object is within a certain distance of my character, it will snap in place to hold on to it.

Thank you again!

1 Like

@yang71 and @yuxemporos Thanks very much!

1 Like