c# – cannot implicitly convert type “void” to “UnityEngine.Vector2”
I am new to C# and have not used Unity that long. I am trying to have a projectile fire at my pointer, but it is firing closer to the base of my pointer. I have tried normalizing it by making a player, but I now keep getting this error and cannot find anything online that can help me
private Rigidbody2D Player;
public Rigidbody2D BallPrefab;
public float attackSpeed = 0.5f;
public float projectileSpeed = 500;
void Fire() {
Player = GetComponent<Rigidbody2D>();
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 playerPosition = Player.transform.LookAt(Input.mousePosition);
Vector2 shootDirection = (mousePosition - playerPosition).normalized;
Rigidbody2D ball = Instantiate(BallPrefab, new Vector2(transform.position.x, transform.position.y),
transform.rotation) as Rigidbody2D;
ball.GetComponent<Rigidbody2D>().AddForce(shootDirection);
Debug.Log(mousePosition);
}
I have been trying to make a playerPosition, but after half an hour of trying different things, I can not figure out what is going wrong.
Read more here: Source link