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 ozg · Jun 19, 2012 at 01:41 PM · c#collisionphysicssphere

How to move an object over a distance in a direction?

Hi.I just want to do a collision with spheres.I've got two spheres and one of them moving to the other. At the beginning there is a distance between them and let's say the distance is 5.(Let's say sphere1 and sphere2).And when sphere1 hits to sphere2,sphere2 must move 5 units only.And this collision must materialize according to physics rules.How can i do that?I tried a lot of things but i'm very new to unity 3D.Because of that i couldn't find a way.Thanks for help.

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

Answer by Ben Ezard · Jun 19, 2012 at 02:54 PM

Add a rigidbody to each of the spheres. Make sure that both spheres have a collider component attached. On sphere1, set the velocity of the rigidbody so that it moves towards sphere2. When sphere1 hits sphere2, the collision will act according to the laws of physics.

Comment
Add comment · Show 2 · 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 Berenger · Jun 19, 2012 at 03:08 PM 0
Share

Good luck to have a movement of precisely 5 units with that. An animation might be best.

avatar image ozg · Jun 20, 2012 at 07:02 AM 0
Share

Is there a way to just move sphere2 5 units in direction of sphere1?This will be enough for me now.

avatar image
0

Answer by keld-oelykke · Jun 20, 2012 at 08:13 AM

I see 3 options depending on what product you want and what kind of solution you prefer:

1) Physics - good for some game mechanics - easy to start at - hard to tweak/fix: Follow Ben's approach and be aware that it will not 100% precise. A game physics engine is good at doing stuff fast and relative correct. It is not the best choice to simulate the law of physics in a precise way; this requires variable simulation steps.

2) Animations - good for visual presentation - easy to tweak - not so flexible: Follow Berengers approach e.g. using the Animation window in the Unity Editor. In this you can move the 2 spheres according to a common time line.

3) Code - expensive but flexible: If you can code scripts you can solve your problem in lots of ways. A code only solution is to encapsulate the behaviour of a sphere into a sphere script, add collision event handling (either by using colliders or math) and code the 100% impulse transfer as you want it to happen.

The best choice is dependent on your situation.

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 keld-oelykke · Jun 20, 2012 at 09:13 AM 0
Share

Is there a way to just move sphere2 5 units in the direction of sphere1?It will be enough for me now.

You can use the Translate method on the Transform component: http://unity3d.com/support/documentation/ScriptReference/Transform.html

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use Physics.IgnoreCollision for multiple objects / toggling collisions for multiple, specific objects? 0 Answers

C# Custom Collision Script (solved) 1 Answer

Physics.IgnoreCollision not working 0 Answers

Why can't my enemies walk up an incline? 1 Answer

Rigidbody Can't Remove Force Directly After Applied 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