Okay, so problem is as follows: I have my player object which is set up in a top down manner, controlled by arrow keys and the graphical part(currently just a box) rotated by looking towards the mouse. Now, all that works fine, now the problem is when i try to pick up an object and set it to be in front of the player, as soon as i click the object a raycast is cast onto the object and the following code is executed, with rayhit being the raycasthit. rayHit.collider.gameObject.transform.position = transform.position; rayHit.collider.gameObject.transform.parent = transform; Once that's done the object goes onto the gameobject with the script, while this works when it's directly on top of the player, this is not the intended result as i want it on a seperate object which will be the same for all the picked up items. my hierarchy is currently set up as follows:
rayHit.collider.gameObject.transform.position = transform.position; rayHit.collider.gameObject.transform.parent = transform;
Now, the odd thing is that when i pick up the object with the script on the pickuppoint, from my understanding the pivot of my 'player model' group should not be affected as the object will be a child of the pickuppoint. the odd thing about it is that it only happens during runtime, since if i parent the pickup object outside runtime the pivot is not affected in the slighest.
now if this didn't interfere with anything movement related i wouldn't be bothered looking this up, but the most frustrating thing about this is that when i look around after the pivot is changed, not only does my playermodel rotate around the pickup object for some weird reason(even though the script is on the 'player model' object), but it also shakes intensely whenever i move the mouse even remotely close to the center, i know the reason for this, being the new pivot which is acting as a rotation point while the aim of the player is trying to look towards the mouse, so, by fixing the pivot problem this goes away too.
I had never once thought a top down pickup would be this rage inducing, as the joy that is the camera parenting pickup system is nowhere to be found as a solution here, but this is truly annoying.
Anyways, if you have any insight as to how i can fix my problem, or some other hierarchy change that allows for a workaround(since i haven't seen any other posts about my problem), i found a video that kinda resembles what i'm going for, but rather than picking it up on top of the player i want the pickup to be in front(holding a shield to block an arrow and such basically, being able to aim it), link to the video: https://www.youtube.com/watch?v=qYcCZiF8Tf8
tl:dr - the pickup is not working for my top down game, please send help.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
3 People are following this question.
Top Down Keyboard Smooth rotation
Why are my projectiles spawning in batches?
Making a 2d game with 3d help
Parenting an object causes it to change rotation
How to attach an object to another object so that moving one moves the other