How to pull and push, jedi-style?

So, for my game, I want to left click to throw the enemy toward me, and right click to send the enemy flying away from me. Can anyone help me with this?


the pushing part should be quite easy if you are using rigidbodies. You just have to add a script, that applies a force, to the object you wish to push/pull. You can see a tutorial on that here. To make the script trigger you can use a raycast and check if the raycast hits anything. Raycasts are explained here.

The pulling part is a bit harder, as you need to make sure that the object you are pulling will not hit you and push you backwards(try creating a trigger around the main character and make the object you are pulling stop or float in front of you if it enters the trigger).

I hope this helped.

Niceee men thanks for your answers !