I’m doing a fishing game where you grab fishes, there 2 Cases:
1-transform the hook to a random place, hit nothing and come to Hook_Source(type=transform).
2-collide with a fish and both objects (fish and hook) transform to Hook_Source.
In order to grab many times, the condition hook.transform.position=Hook_Source.position must be true.
In the first case the hooking (not really hooking) operation works fine and the hook position reset after I transform it. but in the second case the problem is the hook operation works fine, but the hook don’t reset to Hook_Source, there’s about -+0.1 difference in distance don’t know why, which affects my second hook operation, here’s a video explains the situation :
my Collision script ( the script is attatched to the hook(sprite)):
void OnCollisionStay2D(Collision2D coll){
if(coll.gameObject.tag == "fish"){
fish = coll.gameObject;
fish.transform.position = this.transform.position;
StartCoroutine(moveHookBack(Hook_Source, 10f));
}
if(Vector3.Distance(this.transform.position, Hook_Source.position) < 2){
Destroy(fish);
this.transform.position = Hook_Source.position;
}
}