In my game I have an autographic camera at 45 degree angle. I have a sprite bullet firing from point A towards point B.
I want bullet to face the direction of B. I have done that using transform.LookAt. First picture shows what I have.
But sometimes based on the positions of these points the bullet is not clear. What I want to do is rotate the bullet sprite so that its surface is perpendicular to the camera. Second picture shows what I wanted to achieve.
I don’t know how to calculate this. Can anyone help me with this?
I also attached my project to this post (press key “A” to generate the bullet).

First, Change your Prefab Bullet->Plane 's rotation like the follow image

[18082-plane+in+bullet.png|18082]
Add a line in your Init funtion like this
public void Init(Vector3 direction)
{
this.direction = direction;
// change the rotation to face the camera
transform.rotation = Quaternion.LookRotation(-Camera.main.transform.forward);
}
Bug fixed!
Assign this script to the 2D-sprite object in your scene hierarchy and place a camera object in the camera reference field, and you’re good to go!
using UnityEngine;
public class RotateToCamera : MonoBehaviour {
public Camera cam;
void Update () {
transform.rotation = Quaternion.LookRotation(-cam.transform.forward);
}
}