Best way to pick up objects in unity?
Hi....
I have a cube in my scene and i want to pick it up....
its my code on my cube in my "PickUp" function that runs when the reticle enter's the cube:
transform.parent = MyCamera.transform;
But the problem is when i hit the plane by cube and rotate the camera down my Character goes to the air.....
I also assign a Rigidbody to my cube but when i enable "use gravity" i cant pick up my cube and when i disable it when i hit the plane by cube the cube goes to the air!!!!!!!
I tried enabling all of the pivots in "freeze Rotation" and "Freeze position" but it didn't work and my cube has lost its collision!!!!!!!!!
What should i do?!!!
Answer by MrCrumbl3d · May 09, 2017 at 02:17 PM
if you have rigidbody in your cube try "iskinematic" on when you pick up the cube turn on "iskinematic". And Also disable "useGravity". Like:
if(Input.GetKeyDown("space")) { transform.parent = MyCamera.transform; GetComponent().isKinematic = true; }
if doesnt work try to remove the rigidbody. try that and tell me what's happen. Can i have a question are you using "parent = null" to place objects or not?
Answer by exvalid · Nov 12, 2017 at 10:28 PM
link text Note i didnt add throwing but that can be done quite easily now its grabable. i was kinda saving that bit to last
Hey I have added 2 Script to Complete a full Grab toggle and ready to move code,
Fixed An Inversion Error and a Euler read error while moving. since yesterday it is now working as stated below
ObjectGrabIdAndLock, ObjectReplyIdAndMove
ObjectGrabIdAndLock goes on Main player,.. ObjectReplyIdAndMove goes on Moveable Objects remember to add layers in you want to hit in inspector and pick the Headcam Ect
Updated Scripts Since the other week now with full movement And Rotation and Full Inversion Options
This is Complete bar Diagnals and Mouse Rotation as im adding this now, you want to use the option OverideDiagnals and possibly UseDefaultRotation if u hate my defualt.
too add mouse copy the whole auto inversion and paste it underneath and swap the names to the mouse names instead of the default keys its a mission dont attempt it lol. i will do this over the week as still cleaing up the script its pretty large, Please contact at Exvalid@gmail.com To give me job coding.
cheers Ryan kappeslink text Exvalid@gmail.com link text