Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NewToUnity2018 · Dec 22, 2018 at 04:40 PM · scripting problemthird person controllerpick up

Can someone help me with a special pick-up code?

Hello! I'm new to unity and I need a script to carry an object with my third person character and find this script very helpful:

https://answers.unity.com/questions/1419719/how-do-i-allow-3rd-person-character-picking-up-obj.html?sort=votes

But I don't know which object or component I need to assign to the transform guide. And also I think the tempParent is my player's rigidbody, but I'm not sure.. I hope someone can help me. Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jimmycrazyskills · Dec 22, 2018 at 05:22 PM

Hi mate, I had a little look at the script you linked:

  • The 'guide' gameObject seems to be the transform where the item will get moved to.

  • The 'tempParent' gameObject seems to be the object that will be the item's new parent

Example:
If a picked up a sword, the 'guide' gameobject might be a holder on the player's back and the 'tempParent' could be the holder gameObject or the main player's gameobject (depending on how you want the picked up item to move/rotate relative to the player)
Hoped this helped abit =D

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NewToUnity2018 · Dec 22, 2018 at 06:04 PM 0
Share

Hello jimmycrazyskills :)! Thanks for your fast and kind help! I've tried it, but now my character gets stuck to the pickable object... It's a mystery to me... $$anonymous$$aybe I can describe you my outliner: I have a Player$$anonymous$$ovement Rigidbody with the movescript ans pickup script (parent), then a character Rigidbody (child; a 3d model).

Adhering to your instructions I have created an empty object as transform guide (I want the object to carry in front of the stomach and put it there) as child to the Player$$anonymous$$ovement. And I have assigned the whole 3d $$anonymous$$odel of the character as the tempParent. (If I take the character's hand as transform guide, the game crashes).

OUTLINER:

 Player$$anonymous$$ovement (Rigidbody; with movement and pickup-script) = PARENT

 EmptyObject as transform guide = CHILD 1

 3d $$anonymous$$odel as tempParent = CHILD 2

Is this correct? Or does this cause the sticking problem? Would be very nice, if you can help me again :). Thanks and kind regards!

avatar image jimmycrazyskills NewToUnity2018 · Dec 22, 2018 at 10:10 PM 0
Share

Hey mate sorry for the slow reply I was out! , WE WILL GET THIS WOR$$anonymous$$ING ;)
Could you paste your whole script, as it might be easier to find the problem?
If you can't paste it, do you know how/where item is being assigned?
Cheers :)

avatar image jimmycrazyskills NewToUnity2018 · Dec 22, 2018 at 10:56 PM 0
Share

UPDATE Hi again, I've just created this myself and it appears to work ok here's what I did:

Hierarchy:
(Parent) Player GameObject > (Child) Empty ItemHolder GameObject
(Seperate in scene) A cube with an attached Rigidbody
The script component is attached to the main Player GameObject.
The Item variable in the 'Inspector' panel is set to the cube in the scene.
The Temp Parent and Guide variables in the 'Inspector' panel are set to the ItemHolder GameObject
Hope this sheds some light on anything that might be different, if it still doesn't work give us a shout/message :)

avatar image NewToUnity2018 · Dec 22, 2018 at 10:49 PM 0
Share

Hello and thanks again! :) I would be very glad and thankful, if we get this to work :D! I've applied the script to the carry-object, but the carriedObject in the code is also the carry-object, is this ok? Now I can pick it up, but just if the transform guide is the hand of the character and then I just get the outliner of the cube, the mesh lies still on the floor :D. If I apply it to another body part or even if I make an invisble child of the player, the player gets stuck again..

I post the script, but I think it's the same from the link. $$anonymous$$y cube to pick up is a rigidbody with a collider. $$anonymous$$y players parent with the move-script is also a rigidbody with a mesh collider.


using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PickUpObject : $$anonymous$$onoBehaviour { bool carrying; public GameObject carriedObject; public GameObject tempParent; public Transform guide; public float range = 5;

 // Use this for initialization
 void Start()
 {
     carriedObject.GetComponent<Rigidbody>().useGravity = true;
 }
 // Update is called once per frame
 void Update()
 {
     if (carrying == false)
     {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E) && (guide.transform.position - transform.position).sqr$$anonymous$$agnitude < range * range)
         {
             pickup();
             carrying = true;
         }
     }
     else if (carrying == true)
     {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))
         {
             drop();
             carrying = false;
         }
     }
 }
 void pickup()
 {
     carriedObject.GetComponent<Rigidbody>().useGravity = false;
     carriedObject.GetComponent<Rigidbody>().is$$anonymous$$inematic = true;
     carriedObject.transform.position = guide.transform.position;
     carriedObject.transform.rotation = guide.transform.rotation;
     carriedObject.transform.parent = tempParent.transform;
 }
 void drop()
 {
     carriedObject.GetComponent<Rigidbody>().useGravity = true;
     carriedObject.GetComponent<Rigidbody>().is$$anonymous$$inematic = false;
     carriedObject.transform.parent = null;
     carriedObject.transform.position = guide.transform.position;
 }

}


Thanks again!!!!! :)

avatar image jimmycrazyskills NewToUnity2018 · Dec 22, 2018 at 11:01 PM 0
Share

UPDATE Hi again I just replied to your old message so I've re-pasted this, I've just created this myself and it appears to work ok here's what I did:

Hierarchy:
(Parent) Player GameObject > (Child) Empty ItemHolder GameObject
(Seperate in scene) A cube with an attached Rigidbody
The script component is attached to the main Player GameObject.
The Item variable in the 'Inspector' panel is set to the cube in the scene.
The Temp Parent and Guide variables in the 'Inspector' panel are set to the ItemHolder GameObject
Hope this sheds some light on anything that might be different, if it still doesn't work give us a shout/message :)

avatar image NewToUnity2018 · Dec 23, 2018 at 12:02 AM 0
Share

Hi and thanks again! :) I think, there is a problem with the character itself, because if I test your method with a new scene, it works, with my scene, the character takes the object, gets stuck and when he throws the cube, it first goes up about one meter and then it falls on earth. $$anonymous$$y character is child of an empty rigidbody with the movement-script. The character itself isn't a rigidbody and consists of different components. But I can't change that anymore.. $$anonymous$$aybe you have an idea :), or I have to change the hole thing somehow. Definitely I want to thank you for your time and help!! :)

avatar image jimmycrazyskills NewToUnity2018 · Dec 23, 2018 at 12:17 AM 0
Share

Hey again, From what you're saying I'm wondering if it's a collider problem, your movement might be stopping if your Player collider is inside/overlapping with the picked up object.
As a test try moving the Holder Transform quite far away from your Player just to make sure no collisions are happening.
If this still doesn't work give us a shout again or if you can somehow export your project that way I could look at exactly what's happening a bit easier :D

avatar image NewToUnity2018 · Dec 23, 2018 at 12:38 AM 0
Share

IT WOR$$anonymous$$S!!!! :D Yes, it was the collider, now it works just fine :)! Thanks SO $$anonymous$$UCH for your help!!! I hope you have a nice sunday and thanks also for your time, I really appreciate it!! :)

avatar image jimmycrazyskills NewToUnity2018 · Dec 23, 2018 at 12:40 AM 0
Share

WAYHAY! nice one :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

169 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity standard assets third person controller is auto crouching whenever there are objects above. How do I stop this? 2 Answers

Remove keyboard controls from Third Person Controller?? 2 Answers

Problem with gravity in a Third Person Controller 0 Answers

Why when using LookAt to make the turret facing the target it's facing the other direction ? 1 Answer

Animator Trigger Not Working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges