Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 S_Byrnes · Mar 16, 2016 at 09:17 AM · c#2dphysics2daddforceplatform

Move Physics2D Object With Mouse Using AddForce?

Hi all,

I'm having a little trouble finding a solution to this anywhere online. Basically I need to have a 2D platform that catches objects falling onto it, but I need those objects to follow the platform with 100% friction, so I think using AddForce to move the object with a mouse might help.

Right now I have the following script attached to the platform:

 void Update () {
         float distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
         Vector3 pos_move = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen));
         transform.position = new Vector3(pos_move.x, transform.position.y, pos_move.z);
     }

I know there is a method that uses parenting, but I'd like to avoid that, since the objects will be able to land on each other and I don't want an endless list of parents and children and I'd also like them to be able to fall off of the platform too so I don't think parenting is the way to go.

Any suggestions/help would be greatly appreciated! Thanks!

Comment
Add comment · Show 6
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 ComradeVanti · Mar 16, 2016 at 10:15 AM 0
Share

I'm not completely sure what you want to have here...

So your situation is: You have a, for example, 45° tilted platform and want to have, lets say, balls have dropping onto it and then rolling down...

If so, just give your platform 0% friction. I think 100% objects will still roll down 0% friction platforms...

Did iI undertand correctly? If not please give a more detailed discription of the situation :)

avatar image S_Byrnes ComradeVanti · Mar 16, 2016 at 10:27 AM 0
Share

Thanks for the response.

No I don't think you did understand it.

What I have is a flat platform that I need to move with mouse position, and flat objects will fall onto the platform, I need to be able to catch those objects without the object just sliding off of the platform.

avatar image ComradeVanti S_Byrnes · Mar 16, 2016 at 04:01 PM 0
Share

Ah ok I got it now... Well sorry but in my opinion parenting still is the best solution... I mean you can try setting the friction of both materials to 100% and see how that works for you.

Show more comments
avatar image 5c4r3cr0w · Mar 16, 2016 at 11:10 AM 0
Share

I think I get what you want to achieve but there is no need to use AddForce to move your 2D platform. All you need to do is to create physics2Dmaterial with high friction. and add to your platforms 2D Box Collider.

You 'd like to add same physics material to all objects because you wouldn't want them to get slipped and fall down from above each other.

avatar image S_Byrnes 5c4r3cr0w · Mar 16, 2016 at 11:39 PM 0
Share

Thanks for the reply!

I've tried using a physics2Dmaterial though, and nothing changed, the objects still behave as-if the platform is made of the smoothest ice ever.

0 Replies

· Add your reply
  • Sort: 

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

121 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

Related Questions

Question about Scripting a slingshot mechanic 0 Answers

Enemy bounce from screen edges 0 Answers

Transform.translate bullets problem 0 Answers

Object following a path and colliding with other objects with physics. 1 Answer

AddForce with 2D Character 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