- Home /
Attach object to player until button pressed?
First off, I'm not looking for someone to code it for me. Just maybe someone who's done something similar.
What I'm hoping to achieve is have an object (Rigidbody2D) attached to my player object, and when a button is pressed, the object fires, no longer being attached directly (So it doesn't pull the player as well). Later I would add the ability to return the object back to the player object. How would you guys go about implementing something like this? I was thinking joints, but it seems like it would end up messy.
Thanks ahead of time,
Nathan.
Answer by aLovedHater · May 22, 2016 at 12:02 AM
so you are talking about the player having a riigidbody attached to it, but then it fires off of the body when a button is pressed; and your problem is that the whole player moves with it? couldnt you just destroy or change the SetActive of the rigidbody to false, then instantiate a prefab of the rigidbody that you're firing off the player at the firing point? this way when you move the new object that is firing off of your player, the player wont move with it because they are two different objects. (im almost thinking of this as firing an arm off of a player) and if you wanted the "arm" to return to your player then you just have to move it back to the firing point, delete the "arm" object, then re-enable the SetActive of the rigidbody on your player to true so that the "arm" is once again part of your player so that it moves with you.
Oh I see what you mean is set it $$anonymous$$inematic essentially, then re-instantiate it when the button is pressed to simulate it being fired but really a separate object is being fired ins$$anonymous$$d? Seems like it might be a cleaner way of doing it, especially animation wise.
Your answer
Follow this Question
Related Questions
Parent class cannot find component 0 Answers
Make a simple tree 1 Answer
5.1 Interpolation on child rigidbody2d is causing the object to move slower than parent. 3 Answers
Can't refer to a child (with a different tag) when the parent has a rigidbody 2d 1 Answer
Clicking on child executes parent script when Rigidbody2D present? 2 Answers