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 utp · Nov 02, 2011 at 11:45 AM · holding

Holding an object.

hye everyone!,

Im trying to create a script whereby a sphere collider attached on hand(model) and able to pick up a box(rigidbody) and holding it whenever it touched. Currently, im able to make these two thing collide so that whenever the hand swing on the box and it would thrown away. I've tried collider.attachedRigidbody.AddForce(0,1,0) and it comes nothing to happen like i intended to do. Any suggestion to make my character holding an object after touched the box?

hereby my current script which i put it on hand(model):

 function OnCollisionEnter(theCollision : Collision){

     if(theCollision.gameObject.name == "crate"){
      theCollision.attachedRigidbody.AddForce(0,1,0);
 }
 }
 

Thanks guys! ;)

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

2 Replies

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

Answer by syclamoth · Nov 02, 2011 at 11:46 AM

How about-

 if(theCollision.gameObject.name == "crate"){
     theCollision.transform.parent = handObject.transform;
 }

Then, to let go, just set the parent to 'null' again.

Comment
Add comment · Show 7 · 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 utp · Nov 02, 2011 at 03:12 PM 0
Share

Hye Syclamoth,

After i run the updated script, i found that the box got attached to the hand after being touched and follow the hand moving around but then the box was not exactly right in the fixed distance(i mean not nailed at the palm) as the box getting far from the hand and getting funny as well as i move the hand around.

Updated script:

 function OnCollisionEnter(theCollision : Collision){
  if(theCollision.gameObject.name == "crate"){

 //theCollision.attachedRigidbody.AddForce(0,1,0);
 
 theCollision.transform.parent = GameObject.Find("R_Hand").transform;
 
 }

}

avatar image syclamoth utp · Nov 02, 2011 at 03:23 PM 0
Share

Well, yeah, that's going to happen. If you want it to anchor to a specific point, you should create an empty transform which is a child of the hand and has the correct position and rotation that you expect on the box when the player is holding it. Then, when you attach it, do something like this-

 box.parent = anchor;
 box.localPosition = Vector3.zero;
 box.localRotation = Quaternion.identity;

Oh, I forgot to add- if your box has a rigidbody on it, you may want to have this line as well-

 box.rigidbody.is$$anonymous$$inematic = true;
avatar image Fattie · Nov 02, 2011 at 05:57 PM 0
Share

In practice, this will never work. In general in situations like this you need a placeholder transform that holds the object where you want it, and furthermore you need a little routine somewhere that puts the object in the correct orientation. (I see you have added this above! :) )

avatar image syclamoth · Nov 03, 2011 at 12:41 AM 0
Share

Yeah, in practice I would never deter$$anonymous$$e picking up objects by waving a collider at them, either. I'm assu$$anonymous$$g the OP's character has sticky balls for hands or something.

avatar image utp · Nov 03, 2011 at 08:24 AM 0
Share

Thanks syclamoth for the helps,its went well for the box which falling from above(bcoz i put it above model with gravity ticked), however it does not works for the box which sit idle on the floor or the other box hanging next to the model(with is$$anonymous$$inematic and useGravity ticked).

From what i've observed, the box would transform to become the hand children whenever the falling box hit the hand and got attached to it but, unfortunately in other cases when the hand touches the unmoving box(either hanging or on the floor), nothing was happen.

It is like it works with moving box but the other way around when the box unmoving or sit idle.any ideas?

function OnCollisionEnter(theCollision : Collision){

if(theCollision.gameObject.name == "crate"){

 theCollision.transform.parent = GameObject.Find("R_Hand").transform;
 theCollision.transform.localPosition = Vector3(0.5,0,0);
 theCollision.rigidbody.is$$anonymous$$inematic = true;    
 
     }
 }
avatar image syclamoth utp · Nov 03, 2011 at 08:27 AM 0
Share

Collision doesn't work between two kinematic rigidbodies. I would recommend making the one on the floor a non-kinematic rigidbody as well- if it is at rest, it won't go moving on its own in any case. Otherwise, you'll have to use raycasting or some-such thing to manage collisions.

avatar image utp · Nov 05, 2011 at 05:01 PM 0
Share

At last, the box got finally attached to hand either the box moving or sit idle.

 function OnCollisionEnter(theCollision : Collision){
  if(theCollision.gameObject.name == "crate"){
  theCollision.transform.parent = GameObject.Find("R_Hand").transform;
  theCollision.transform.localPosition = Vector3(1.25,0,0);
  theCollision.rigidbody.is$$anonymous$$inematic = true;    
   }
 }

Thanks Syclamoth and others for much helps!

avatar image
0

Answer by exvalid · Nov 12, 2017 at 10:25 PM

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

ObjectReplyIdAndLock, ObjectGrabIdAndMove

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


objectgrabscripts.zip (11.7 kB)
Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

Command for Holding a Key Down & Shift Key 2 Answers

Displaying GUI question? 1 Answer

making a climbable boss in 2d 2 Answers

rigidbody on the character 0 Answers

mouse Down+Hold and double click events 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