- Home /
The question is answered, right answer was accepted
Have a billboardsprite face camera while keeping collider grounded
Hi everybody. I'm new to developing and programming in Unity and I believe I've finally come to a roadblock I need help with. Here is the basic gist of my scenario:
I'm developing a game where the environment is 3D but the player and the enemies are sprites. Both the 3D and 2D assets are viewed through an orthographic camera that follows the player sprite whenever it moves and the player can rotate the camera around the player within a set radius, so I need to make the player sprite into a billboard sprite so that the sprite always faces the camera no matter how the camera is rotated around it. I've already created the script needed to do this, which is as follows:
public Transform MyCameraTransform;
private Transform MyTransform;
public bool alignNotLook = true;
// Use this for initialization
void Start()
{
MyTransform = this.transform;
MyCameraTransform = Camera.main.transform;
}
// Update is called once per frame
void LateUpdate()
{
if (alignNotLook)
MyTransform.forward = MyCameraTransform.forward;
else
MyTransform.LookAt(MyCameraTransform, Vector3.up);
}
}
This is the script needed to make the sprite face the camera always. However, because of the way ".Lookat" behaves, the entire transform of the player object faces the camera and not just the sprite. This means that the box collider I have attached to my player object faces the camera as well, which causes the object's physics to act strange, ie the object moves up and off of the environment instead of just staying and moving on it. I have attached two pictures to show the behavior:
I have researched to see if there is a way to have just the sprite image face the camera and not the whole transform of the object face it, but I can't seem to find anything on this particular scenario. I have tried to mess with the box collider on the object and have even changed it to capsule and sphere colliders to see if it would help with the problem at all, but no luck. I'm at a lost as to what I should do now. Is there a way to change the script to make it so that only the image is facing towards the camera? Should I be attaching another type of component to instead of a collider? Any advice or suggestions would be appreciated.
EDIT: Just found out what billboard shaders are. Guess I don't need the scripts anymore!
Follow this Question
Related Questions
Position in relation to another object 1 Answer
Moving a 2D character along the X and Z axis only. 1 Answer
How can i make terrains from 2d map images 0 Answers
How to show a 2D texture through a 3D object like it's a portal? 1 Answer
Camera display specifications,2D visuals in a 3D game with camera issues 0 Answers