Goal: I am trying to create an attack towards the mouse click with an offset of the player.
What works: instantiates the object at the correct angle towards the mouse click.
Whats not working: currently the object is spawned close to the mouse click and not offset.
How can i get it to offset it a fixed distance away from the character while still keeping its angle?
public IEnumerator Attack()
{
Vector3 mPos = Input.mousePosition;
mPos.z = Camera.main.nearClipPlane;
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(mPos);
float angle_ = (Mathf.Atan2(transform.position.y - worldPosition.y, transform.position.x -
worldPosition.x) * Mathf.Rad2Deg);
float trueAngle_;
if (angle_ < 0)
trueAngle_ = UnwrapAngle(angle);
else
trueAngle_ = WrapAngle(angle);
Vector2 cPos = new Vector2(transform.position.x, transform.position.y);
Vector2 dirVector = new Vector2(worldPosition.x + cPos.x, worldPosition.y + cPos.y);
GameObject swing = Instantiate(slash, dirVector, Quaternion.AngleAxis(trueAngle_ + 90, Vector3.forward)) as GameObject;
yield return new WaitForSeconds(.317f);
Destroy(swing);
}