It's probably not the most enticing headlining you've ever read, but it might be of some interest for some! I first saw this effect used in Half Life 2, where they use a flat 2D image and then use code to have it always be positioned towards the camera (so you never see it's flat). Actually thinking about it a little more, all of the enemies in Doom were created in this way. Where as in Half Life 2 they used it sparingly and effectively, I've gone completely over the top and just copied and pasted like there's no tomorrow. I'll be a bit more subtle next time I promise. Here you can see the position change a little clearer:
The images were created from DALL-E (using prompts like 'bush single branch with leaves flat 2d albedo texture on black background'). From here I adjusted the image in Affinity designer:
In unity you need to change the image type to 'Sprite 2D & UI', get the Alpha Source from 'Grey Scale', generate Mip Maps and change the max size to something like 256. The Alpha source is important here, as that's what removes the black background.
The C# script is very simple:
public class LookAtPlayer : MonoBehaviour
{
public GameObject player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.LookAt(player.transform);
}
}
{
public GameObject player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.LookAt(player.transform);
}
}
We declare a public variable, which when back in Unity, we drag the main camera onto.
And that's all there is to creating performant grass!
No comments:
Post a Comment
Say something...