I am trying to code a dash attack, where the player dashes through the target enemy.
I’ve attached a quick diagram showing the part im stuck on.
Basically I have the player and enemy positions, and im trying to find a Target Position behind the enemy based on an adjustable follow through distance.
Any help/suggestions are greatly appreciated <3
you can use the condition of physics.raycast (DOC: Unity - Scripting API: Physics.Raycast), simply you draw a ray to the dash direction and if the player hit the enemy, he was attacked
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, dashDistance)
//you can use a custom tag to check if the hit was an enemy
if(hit.gameobject.tag == "Enemy")
Debug.Log("The enemy was attacked");
//here you will move the player to the dash point
I hope this can help your question
To find the heading to any vector from another its simply
heading = subject - self;
So the heading vector (a vector which is in the direction of the subject from your self and has a length equal to the distance between you and the subject … would be
var heading = enemy.position - player.position;
You can now set your target position according to that direction e.g.
var targetPos = enemy.position + (heading.Normalized * followThruDiistance);