Using Raycasting for a 'Boomerang' attack in 2D C#?

Hello there!
First off I’d like to say this is my first time developing a game in 2D in unity, as I recently upgraded from Unity 3.5.5 (It was for a college project) and decided to upgrade to Unity 5 and I was wondering: Is it possible to use raycasting to create a ‘boomerang’ attack? Would this be more suited for something made in a 3D environment or should I stick with 2D?

I also haven’t started working on the code as this is my first time working with a raycast, too.

(‘Boomerang’ as in something that travels along the raycast and comes back to the player before ending, think of something like Ahris ‘Orb of Deception’ ability from League of Legends)

No real reason for a raycast at all, I don’t think.

Propel the boomerang forward and after a certain amount of time has passed, have it travel back to the player.

Alright, fair enough I suppose… Any recommended ways to propel the boomerang?

Depends on your setup - are you using rigidbodies with forces? Rigidbodies with velocities? Moving transforms by yourself?

I tend to use Rigid body with forces, namely because I find it easier to manage player gravity with it.

You’d probably want to disable gravity on the boomerang itself.

So just create a force vector relative to your aiming direction (towards the mouse? straight ahead of the player? I’m not sure of what 2D perspective you’re using) and use AddForce() to apply it. Returning the boomerang is the same thing just with a vector back to the player.

I’m planning on having the boomerang instantiate in-front of the player (by which I mean like, to the right/left of the screen, depending on which way they’re facing).

Thanks allot though! I hadn’t thought about using AddForce.

If you run into any issues, just post your code and myself or someone else will help you work through it.

Best of luck.

1 Like

Thanks allot, you’ve been quite helpful! :slight_smile: