- Home /
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!
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 :)
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.
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.
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.
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.
Your answer
Follow this Question
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
Multiple Cars not working 1 Answer