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 dominique · Jan 20, 2011 at 03:53 PM · collisionobjectmovesettings

Move object with collision

hello guys

I'am new @ unity so i need some help. I want to move a object from point a to point b but this with a other object. For example:

My object a hand picks up a box then walks (or floats) from that point lets call it point a to a other point lets call it b. Then drops it or whatever. What is the best way to do this i'm somewhat formiliar with javascript and c#.

Any suggestions of samples

thnx in advance

Comment
Add comment · Show 1
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 Scribe · Jan 20, 2011 at 03:59 PM 0
Share

do you want to pick up the object with a button press or what are the circumstances. if so you could try doing and on button press and then parent the object you pick up to the hand it would then travel with the hand

1 Reply

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

Answer by Scribe · Jan 20, 2011 at 04:12 PM

var SpawnTo : Transform; //your hand

var Object1 : Transform; //what your picking up

var dist = 5; //distance at which you can pick things up

function Update () {

 if(Input.GetKey(KeyCode.Q)){

     if(Vector3.Distance(transform.position, Object1.position) < dist){

Object1.parent = SpawnTo;

Object1.transform.position = SpawnTo.transform.position;

Object1.transform.rotation = SpawnTo.transform.rotation;

     }
 }

}

i think this would work. basically it checks whether you pressed a button i chose 'Q' but you can choose whatever you want. it then looks at your distance from the object and whether you can "reach it" (in this case i chose a distance of 5)

if both of the cases are true the object is parented to the 'SpawnTo' which can be your hand and its position and rotation are also set to it.

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 efge · Jan 20, 2011 at 04:07 PM 0
Share

(As Scribe recomended) Search the answers for Parenting.

Or take a look at FixedJoint.

avatar image dominique · Jan 21, 2011 at 09:38 AM 0
Share

thnx alot this really helps

avatar image dominique · Jan 21, 2011 at 09:42 AM 0
Share

thnx guys for the answers it really helpt gonna use the script from scribe thanks for that. Also gonna look into FixedJoint.

really appriciate it.

avatar image dominique · Jan 21, 2011 at 11:02 AM 0
Share

Hello Scribe i got a question when i use Q in the script i get a error: object reference not set to an instance of an object moveObject.Update() not formiliar with errors in unity yet, this is the error line if(Vector3.Distance(transform.position, Object.position) < dist) Any tips ?????

avatar image Scribe · Jan 21, 2011 at 04:36 PM 1
Share

var SpawnTo : Transform; //your hand var Object1 : Transform; //what your picking up var dist = 5; //distance at which you can pick things up private var isHolding = false;

function Update () { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Q)){ //if you press 'q' if(Vector3.Distance(transform.position, Object1.position) < dist) //if distance is less than dist variable { isHolding = !isHolding; //changes isHolding var from false to true } }

 if(isHolding == true){
     Object1.rigidbody.useGravity = false; //sets gravity to not on so it doesn't just fall to the ground

     Object1.parent = SpawnTo; //parents the object

     Object1.transform.position = SpawnTo.transform.position; //sets position

     Object1.transform.rotation = SpawnTo.transform.rotation; //sets rotation
     }
     else{ //if isHolding isn't true
         SpawnTo.transform.DetachChildren(); //detach child (object) from hand
         Object1.rigidbody.useGravity = true; //add the gravity back on
     }

}

supped up my old script and this worked perfectly for me when my object that i want to move has a rigid bodythat usually has gravity

hope this helps

scribe

avatar image dominique Scribe · Jan 24, 2011 at 08:27 AM 0
Share

Hallo Scribe thnx for the solution your a life saver really appriciate your effort

avatar image Scribe dominique · Jan 24, 2011 at 05:41 PM 0
Share

you are welcome :) glad I could help if you feel your question has been answered please click the tick next to the accepted answer then people will know to look here if they have the same question as you (i also get reputation points :D)

Show more comments

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

changing pivot's placement 2 Answers

What am I doing wrong? 1 Answer

colliding with 2 objects at a time 1 Answer

Detect collision with specified object 1 Answer

Objects Touching? 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