I’ve been trying to figure out how to do this for more than 30 minutes but nothing seems to work, what I’m trying to do is have an enemy shoot at the player.
float angle;
Transform player;
void Attack()
{
float angle = Vector3.Angle(transform.position, playerT.position);
Instantiate(attack, enemyV, angle);
}
This says it can’t convert float to quaternion, i’ve been looking up how to get the angle in quaternion, can’t find anything.
I’m also a bit confused why people keep saying to use Vector3 for 2D games instead of Vector2.
As you might have figured out, I’m a bit of a scrub, just barely started learning.
There’s two issues here:

Vectors can represent either positions or directions. Vector3.Angle gives you the angle between two directions, so it will interpret those positions you’re giving it as directions from the origin to the player and from the origin to the enemy.
In this case, you want to calculate the direction from the enemy to the player:
Vector3 dir = playerT.position  transform.position;
…and then do an ArcTan to calculate the angle (if schools explained how trigonometry is used ALL THE TIME in video games I’m sure kids would pay more attention…):
float angle = Mathf.Atan2( dir.y, dir.x ) * Mathf.Rad2Deg; // Assuming you want degrees not radians?
You may have to trial and error a bit to make sure it works in all directions.

The Instantiate takes a quaternion which is an arcane but mathematically reliable representation of a rotation. Our normal human brains cope much better with euler angles (x,y,z rotations). Especially since in 2D you only want it rotated around the Z (into the screen).
Quaternion q = Quaternion.Euler( 0f, 0f, angle );
Instantiate( attack, enemyV, q );
Vectors are a set of numbers commonly used for coordinates. For most things in 2D Vector2 is fine, but UNity is a 3d engine, so even if you are making a 2d game you can rotate and move sprites in 3 dimensions. Post your error next time it took me a while to see what line the error was on, but I think it’s Instantiate(attack, enemyV, angle); the angle parameter is probably expecting a quaternion. I think you should write out what you are trying to accomplish, there is probably a much easier way to do it.
Hello, thanks for the responses, I managed to get it sort of working thanks to you guys with this:
public GameObject attack;
public GameObject enemy;
Vector2 enemyV;
public Transform playerT;
public Transform enemyT;
float projSpeed = 20;
void FixedUpdate()
{
Attack();
}
void Attack()
{
enemyV = transform.position;
Vector3 dir = playerT.position  transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion q = Quaternion.Euler(0f, 0f, angle);
GameObject attackGO = Instantiate(attack, enemyV, q);
Rigidbody2D rb = attackGO.GetComponent<Rigidbody2D>();
rb.AddForce(transform.right * projSpeed, ForceMode2D.Impulse);
}
It’s very bare bones, it fires on every FIxedUpdate just so i can test it out. The attack is rotated towards the player, but it doesn’t go in the direction of the player, i tried transform.right and transform.up but those didn’t work either.
I’d like to go into detail on your responses but it’s really late and I’m really tired, just wanted to post this before bed.
edit: nevermind, using AddRelativeForce and transform.right it now works