I have followed one of the Brackey’s tutorials on collider effectors and used the point effector to act as a magnet for my player to collect items.
My question is there something I could add to my script to make sure the item will definitely come to the player. If I set the force magnitude below -1, it will do a circle around my player and then drift off into space. I would like to set the magnitude to about -10 and still ensure the item hits the middle of the player collider.
I added a point collider effector to the object and set magnitude force to 0 and a point collider effector to the player with force magnitude of -1.
You could use an inverse-squared force-mode and adjusting the force-scale which might help but depending on how it’s set-up it might even make the situation worse. It really depends on what you’re doing here If all you want is to move an item towards the player using an effector seems like overkill. Maybe it’d be far easier to manipulate the items position towards the player using Rigidbody2D.MovePosition over time. If you’re not comfortable doing that then there’s a more “automatic” method of using the TargetJoint2D which you’d temporarily add to the item then set its target position. The force used here can be configured so the item moves as slow or fast as you like. The nice thing about the joint is that you can anchor it away from the center-of-mass which makes it look like you’re picking it up from any position as it’ll rotate.
I have a test project here which (amongst other stuff) demonstrates the TargetJoint2D. In this case it’s mouse following/dragging but the concept is the same. In your case the position isn’t the mouse, it’s the player position or a point moving towards the player.
I was never expecting to get such a good answer. I love your demo of the targetjoint2d, very cool way to demo it. I will have a go at using the joint target, and let know how I go.
Thank you for your help!