I’m currently spawning my object at my players location. I want to spawn it a distance in the direction of the mouse.
public GameObject shot;
Transform playerPosition;
Vector2 target;
Vector2 targetVector;
Transform shotPosition;
void Start () {
playerPosition = GetComponent<Transform> ();
}
// Update is called once per frame
void Update () {
target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
// Target location - current location
targetVector.x = target.x - transform.position.x;
targetVector.y = target.y - transform.position.y;
//shotPosition.position = new Vector2 (targetVector.normalized.x, targetVector.normalized.y);
if (Input.GetMouseButton(0)){
Instantiate (shot, shotPosition.position, Quaternion.identity);
}
}
I changed playerPosition to shotPosition in instantiate. The targetVector gives me the x and y values away from my playerPosition where shotPosition should be. How do I add my targetVector to my player position