Controller/Mouse ranged and melee attacks solution

For controller support melee and ranged will use a button to switch between weapons. For Keyboard it will use a key. The player will have a melee weapon equipped and a ranged weapon equipped if one is in the inventory. If the player has no ranged weapon, it will be melee only.

The distance will change with attack type selected depending on the weapon used. If the player is to far away for the ranged weapon will not use auto-aim.

When a melee weapon is selected the cone extends the range of the window. The player will run up to the enemy and attack.

How this is done is using a collision cone extending from the players front facing. The cone length will change depending on the attack range that is determined by the weapon in use. If an enemy is in the cone, the player auto-aims at the closest enemy. If there is time an option will be added to cycle through enemies in the cone if there are more than one.

The enemy will get a red highlight when in range so the player knows they can attack.

This will work the same for mouse/KB.

Privacy & Terms