Collecting Pickups
Drawing Pick ups to the player.
Objective: When the ‘C’ key is pressed by the Player,Pickups quickly move to the player.
I edit the Project Settings ->Input Manager -> Fire 3 to be the c key.
I add an Input Axis String, a Bool for if the power up should move towards the Player and the fields needed to use for Physics 2D BoxCast.
In the Update method I set the should move towards target to if the Fire3 button is pressed.
In the Fixed update If the PowerUp should move towards the target I use BoxCast to get a target. If there is a target I move the PowerUp towards the target.
Now when I press the C key and the PowerUps in the scene are attracted to the Player, But be careful as you might get a power up you don’t want.