I’m trying to make it so when the player hits attack, they swing (and check for targets) in the direction they’re holding the WSAD keys/analog stick. So if the player hits attack while holding D, the game will check for hits in the cone starting in the model’s transform.right:
for (int i = 0; i < defenderList.Count; i++){ //Iterate through the list of enemies that are in range
if (Input.GetAxis ("Horizontal") == 0 && Input.GetAxis ("Vertical") == 0){ //If the player isn't holding any movement key
playerAttackAngle = Vector3.Dot(directionToTarget, transform.forward); //Take the dot product of the direction to target + player's forward
}
else{ //If the player IS holding a movement key
playerAttackAngle = (Vector3.Dot(directionToTarget, new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical")) ) ); //Take the dot product of the direction to target plus the direction of the vector formed by the WSAD keys the player is holding
}
if (distanceToTarget <= attack.range && (playerAttackAngle > attack.areaOfEffect)){ //Double check that enemy is in range, and inside the player's attack cone
//Message enemy that they've been hit
}
}
However, I can’t seem to make this work: enemies are correctly hit if I stand in front of them and don’t move, but when I hold any direction, enemies in the direction I’m holding don’t register the hit. Am I doing my vector math wrong?