Magnetic object to make coins move to object

I’m trying to make an object that is moving at various speeds to be magnetic and if it gets close enough to a coin it will suck it in towards the object.

What I have right now works kind of:

distance = Vector3.Distance(transform.position, junk.transform.position);
    		
if(distance <= 35 && !destroySequence) {
    destroySequence = true;
}
if(destroySequence && !moving) {
    moving = true;
    iTween.MoveTo(transform.gameObject, iTween.Hash("x", transform.position.x, "y", junk.transform.position.y, "z", junk.transform.position.z,"time", 1.0f, "oncomplete", "destroyCoin"));
}

It moves the coin to my object which is sometimes moving a very fast rates and the object will move past the position that the coin is suppose to move to so the object is usually in front of the coins when they reach the position.

So what I tried is if the coins hit the object, that it destroys the coin. But what I found is the coin almost never hits the object. I’ve been doing a lot of searching on the internet and can’t find what I am looking for. I also tried lowering the time on the iTween but that makes it so quick you can’t even see it, and it still has that same issue above.

If you don’t understand think of Temple Run and the magnet power-up and how it sucks in the coins. Something like that.

Thanks.

Make your coin a Rigidbody and try AddForce to the coin.
So you need to try first because I did not…
The idea is that you have a trigger sphere around the coin. When the magnet gets in, you start calculation. You already have a reference to the transform of your magnet.

What you do is get the magnitude of the vector between the coin and the magnet. Use a linear equation to define an index. Then you pass all the required variable to AddForce.
This way, as you get closer to the magnet, magnetField.magnitude gets smaller->index gets bigger->the force gets bigger. You might have to change the force value as well

bool inside;
Transform magnet;
float radius = 5f;
float force = 100f;
void Start(){
   magnet = GameObject.Find("Magnet").GetComponent<Transform>();
   inside = false;
}
void OnTriggerEnter(Collider other){
   if(other.gameObject.tag =="Magnet"){
   inside =true;
}
void OnTriggerExit(Collider other){
   if(other.gameObject.tag =="Magnet"){
      inside =false;
}

if(inside){
   Vector3 magnetField = magnet.position- transform.position;
   float index = (radius-magnetField.magnitude)/radius;
   AddForce(force*magnetField*index);
}

Try to associate it with *time.deltatime just like we are doing in Rotation like stuff…and i am not so sure But your problem will be solved by that…