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 austen · Mar 12, 2011 at 01:59 AM · physicsparentpickup

trouble with parenting

i want to instantiate an object, im using

if (Input.GetButtonDown("Fire1"))
    Instantiate(newObject, transform.position + transform.forward * 2.0 , transform.rotation);

after instantiating i want the object to stay in front of my player while i am walking around, then when i want to drop it i will click the mouse again. i think i have to use something like:

myObject.transform.parent = gameObject.FindWithTag("player").transform;
myObject.GetComponent(Rigidbody).isKinematic = true;

i cant even get the object to stay in my view while im moving it just drops to the ground or stays in one spot. any help is appriciated thank you

Comment
Add comment · Show 2
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 Myth · Mar 12, 2011 at 02:06 AM 0
Share
  • possibly disable the rigidbody component when you pickup the object and enable again when you drop it.

Doing this should get rid of the gravity when you are moving it.

avatar image hypnoslave · Mar 12, 2011 at 07:09 AM 0
Share

trouble with parenting eh?

trouble with parenting eh..

 if(child.is$$anonymous$$isbehaving)
   parent.ThreatenToRemovePrivilages();
 else
   parent.RewardBehaviorWithAffection();

I know, I'm hilarious

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Mar 12, 2011 at 04:19 AM

Since you only posted some snippets of your code I can't really figure out what exactly you're doing wrong, but i guess you work on the wrong object. Instantiate takes as first parameter a object that should be cloned (can be a prefab). The function returns the new created clone.
Also it's not clear to which object your script is attached. If it's attached to the player don't use FindWithTag it's not necessary. So your script could look like:

var newObjectPrefab : GameObject; // Assign object prefab to this var private var currentObject : GameObject = null;

function Update() { if (Input.GetButtonDown("Fire1")) { if (currentObject == null) { currentObject = Instantiate(newObjectPrefab, transform.position + transform.forward * 2.0 , transform.rotation); currentObject.transform.parent = transform; currentObject.rigidbody.isKinematic = true; } else { currentObject.transform.parent = null; currentObject.rigidbody.isKinematic = false; currentObject = null; // To be able to spawn another one } } }

Comment
Add comment · Show 1 · 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 austen · Mar 13, 2011 at 10:20 PM 0
Share

thank you so much this helpped me a lot!

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

Turret Limitations on a Moving Object 0 Answers

Weapon passing through colliders (objects)? 0 Answers

Boolean being constantly redefined? 2 Answers

How to set up items- triggers with rigidbodies 2 Answers

Moving child transform also moves parent rigidbody 0 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