Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 $$anonymous$$ · Dec 03, 2017 at 09:13 AM · 2dvectorspringjoint

How do I make one object go in the same way and with the same speed as the other object?

Hi. I'm 'throwing' one object using the SpringJoint2D. How can I make other object go with the same speed as of this one? (and in the same direction)

Comment
Add comment · Show 4
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 pako · Dec 03, 2017 at 09:31 AM 0
Share

It depends on how you want to use it, but the easiest thing would be to make it a child of the first object.

avatar image $$anonymous$$ pako · Dec 03, 2017 at 02:19 PM 0
Share

I want to just throw this object in the same direction and speed as of the other object and then let it go.

Can you suggest something else? I was trying to use AddForce() function but it doesn't really work the way I need it to.

avatar image pako $$anonymous$$ · Dec 03, 2017 at 02:58 PM 1
Share

It's still not clear to me exactly what you want to do, especially because with a spring joint the speed constantly changes, and the direction may also change all the time. So, from what you've said, I can only assume that you want the speed and direction of the object thrown first (object1), at the point in time that the second object (object2) is thrown.

So, here's some example code:

     private Rigidbody rigidbody1;
     private Rigidbody rigidbody2;
 
     private Vector3 object1Velocity;
 
     private void Awake()
     {
         rigidbody2 = GetComponent<Rigidbody>();
     }
 
 
 
     //$$anonymous$$ethod to call for throwing Object2
     void Throw()
     {
         //You must tag Object1 so that you can find it from Object2
         rigidbody1 = GameObject.FindGameObjectWithTag("Object1").GetComponent<Rigidbody>();
         object1Velocity = rigidbody1.velocity; //read the speed and direction (velocity) of object1
 
         rigidbody2.velocity = object1Velocity; // assign it to the velocity of object2.
     }
Show more comments

1 Reply

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

Answer by BloodMarked · Dec 03, 2017 at 03:26 PM

there are multiple ways to do this, depending on what components you use and what behaviour you want


1) if you are using rigidbodies:

object2.GetComponent().velocity = object1.GetComponent().velocity;


2) storing the difference, then updating it every frame:

Start:

Vector3 difference = obj2.transform.position - obj1.trandform.position;

update:

obj2.trandform.position = obj1.transform.position + difference;


3) make it a child of the thrown object?

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 BloodMarked · Dec 03, 2017 at 09:56 PM 0
Share

should be GetComponent<Rigidbody2D>() ins$$anonymous$$d. but it vanishes when editing the answer

avatar image pako BloodMarked · Dec 03, 2017 at 10:49 PM 0
Share

The angle brackets show only if you use the 101010 button.

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

139 People are following this question.

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

Related Questions

How do I work with Synfig animations in Unity? 1 Answer

Game Objects same transform.position value, sitting on different places 2 Answers

How to limit the directions an object can move? 2 Answers

Alternative to vector graphics for 2D 1 Answer

Spring Behavior Unity 2d Scene 2 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