Boomerang script, help needed on the return

Hello! I’m prototyping a 2D 1v1 fighting game and i wanted to include a boomerang ability in the project but I need some help. The help needed is actually about this piece of code :

destination = new Vector2(transform.position.x - boomerang.transform.position.x, transform.position.y - boomerang.transform.position.y);
boomerang.GetComponent<Rigidbody2D>().velocity = destination * projectileSpeed;

I would like that the boomerang keeps a constant speed but still goes in the correct direction. By that I mean that the speed of the boomerang should not be affected by the distance between the player and it but only by the projectile speed variable. The difference between the player’s and the boomerang’s position should be only used to show the boomerang where it is supposed to go. I’ve already tried some ways to fix it but none of them actually worked.

If you coul help me I would be very pleased, thanks :slight_smile:

Does destination get calculated every frame?

The destination should only be calculated once, when then Boomerang spawns, e.g. in the constructor or BeginPlay().

You can normalize the Vector2 (or Vector3):


Privacy & Terms