0
\$\begingroup\$

I make a 2.5D first person game like Doom, Duke Nukem 3D, and Daggerfall used to be. I'm new to Unity and game development in general, so I'm sorry if this seems obvious to some people.

What I want is to have the 2D sprites of the trees to billboard smoothly in the same way they did in the old games. Take a look at this video to understand what I mean: https://www.youtube.com/watch?v=xPwGXf8y6XA&t=277s

I've already tried the proposed solution at http://wiki.unity3d.com/index.php?title=CameraFacingBillboard and it doesn't work the way I want, it's uncanny and off-putting the way it works.

Please help me.

\$\endgroup\$
1
\$\begingroup\$

I found a way to come closer to the desired result, but still not perfect.

Here is my code:

    var targetPosition = m_Body.transform.position;
    targetPosition.y = transform.position.y;
    transform.LookAt(new Vector3(m_Body.transform.position.x, transform.position.y, m_Body.transform.position.z));

Where m_Body is the GameObject on which the Camera is attached to.

\$\endgroup\$
  • 1
    \$\begingroup\$ What exactly is "not perfect" about it? If you describe what exactly bothers you with that solution, someone might be able to suggest an improvement. \$\endgroup\$ – Philipp Feb 14 '17 at 15:04
  • \$\begingroup\$ The thing is that while from far away it is rather OK, when the player gets closer, the billboarding effect becomes more noticeable. Especially if lets say the player gets right next to the tree and tries to touch the 'branches', the branches will move away as the tree rotates around its vertical axis. What I came up with is to use a OverlapSphere() to see if the player is in a certain radius from the tree, and if the player gets close enough to turn billboarding off so as to avoid this. \$\endgroup\$ – Stavros D Feb 15 '17 at 18:30
  • \$\begingroup\$ @Stavros make multiple billboards for different rotations. That's what older games did. \$\endgroup\$ – Bálint Mar 17 '17 at 9:45
  • 1
    \$\begingroup\$ Pretty much ALL older games had one issue or another with billboarding looking fake. \$\endgroup\$ – Draco18s Apr 18 '17 at 4:36
0
\$\begingroup\$

If you want billboarding to work on CPU, you can use predefined methods like Transform.LookAt. The replicated effect from Transform.LookAt could be achieved using Rotate or setting the rotation of game object. You can use either euler angles or Quaternion the second one is the recommended one to avoid different difficulties including Gimbal Lock problem.

You could calculate the effect on GPU using shaders - see this for more information: Efficient billboarding sprites in unity.

\$\endgroup\$
  • \$\begingroup\$ But how is this the right way to do it since this way doesn't get me the result I want ? :/ \$\endgroup\$ – Stavros D Feb 14 '17 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.