Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Top down object pickup

$
0
0
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: https://gyazo.com/d7c86c0dd6365e6bbec14b25e88442bb 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.

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>