Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 CptKittens · May 09, 2011 at 05:28 PM · 2dobjectparentingpickup

Picking up Objects in a 2.5D game. Help!

I am having trouble finding any tutorials of answers on how to even begin to set up a pick up object script in my game. My game is simple and so is my objective. I have one GameObject with a character controller attached the Lerpz PlatformerController script. This is the player and I want this player to be able to pick up objects in my game in real-time i.e hover infront of the character and be able to place them in other areas in the game stage.

If there is a tutorial or simple script/method I can work with I would greatly appreciate it and to see the project so far for an idea of what I am working please follow this link.

http://www.youtube.com/watch?v=kc2jduUTt1c

This is just a demo and my game premise is slightly different, I want the pink ball to be trapped by locked doors (similar to the yellow ones in the demo) but the green ball to pick up objects (Keys) and place them in triggers to unlock the doors.

Thanks

UPDATE

I have been trying this code

   function OnTriggerEnter (other : Collider){
if (other.CompareTag("Player"))
    {
other.transform.parent = transform;
}
}

and have been attaching it to my Player. Yet when my Player touches the Object that is the trigger the Player becomes a child of that object. I want it to be the other way round yet when I try and change the CompareTag to "Object" (The name of the item I want to pick up) it says that the TAG HAS NOT BEEN DEFINED although that Game Object is name "Object".

Any ideas where I am going wrong?

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
1
Best Answer

Answer by Dave 11 · May 09, 2011 at 07:00 PM

At the collider of the object you want to pickup tick the box is Trigger, then use the function onTriggerEnter() { //do stuff, run checks, etc. } and attach this to your player character.

Edit: Nothing sounds nooby, I'm still learning myself too :) I assume you actually want to attach it to your player?

function OnTriggerEnter (other : Collider){ 
 if (other.transform.name == "NameOfTheObjectToBePickedUp") { 
  other.transform.parent = transform.Find("TheObjectYouWantToMakeItAChildOf"); 
 } 
}

Comment
Add comment · Show 3 · 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 CptKittens · May 09, 2011 at 07:44 PM 0
Share

Im sorry if this sounds nooby but can you elaborate a bit more. I understand the onTriggerEnter statement but in terms of the command after I am a little lost. How would I begin to parent it? I was trying to use this script but do not know if it is the right direction for what I want?

function OnTriggerEnter (other : Collider){ if (other.transform.tag == "$$anonymous$$oveable") { other.transform.parent = transform.parent; } }

avatar image CptKittens · May 09, 2011 at 09:55 PM 0
Share

Cheers very much, I had been working with the script above on my UPDATE and was only a tiny variation to what you said. SO nearly go there ;)

Thankyou much I appreciate it :)

avatar image Dave 11 · May 09, 2011 at 09:56 PM 0
Share

No problem and good luck!

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

No one has followed this question yet.

Related Questions

Making an object a child on collision 1 Answer

Dragged object keeping it's original rotation. 0 Answers

Transparent Texture2D 2 Answers

How do I move my 2D object using arrow keys ? 4 Answers

i want the camera stop follwing my player only on y axis when he jumps... 4 Answers


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