So, I want to make a game where the player can click on different objects and be pulled towards them. To achive this, I used this code:
void FixedUpdate ()
{
if(Input.GetMouseButton(0))
{
// Move the player
Rigidbody2D playerRigBod2D = thePlayer.GetComponent<Rigidbody2D>();
playerRigBod2D.AddForce(transform.position - thePlayer.transform.position);
// Draw a line towards the player
GetComponent<LineRenderer>().SetPosition(1, thePlayer.transform.position);
}
}
This works fine with just one object of this prefab, but once I add more, the player gets pulled to the point in between these objects. I can't quite make out why, since transform.position should be unique to each of the objects that have this script applied right?
I'd be thankful if one of you could shed some light on this, thank you :)