Hello Guest

Author Topic: Sprites clipping into 3D objects  (Read 5951 times)

Crispy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Sprites clipping into 3D objects
« on: January 27, 2013, 09:36:10 pm »
I'm using 2D sprites in a 3D environment, but I'm having problems with the sprites clipping into the 3D walls. I have a script on the sprites that makes them rotate to "face" the camera as it orbits vertically. However, the 3D walls do not rotate, and therefore the sprites will sometimes clip into the walls.

Here's an example of this:


Is there any elegant solution to have the sprites render fully, even if they're clipping through something?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprites clipping into 3D objects
« Reply #1 on: January 27, 2013, 09:37:23 pm »
You still want them to be obscured by other objects though don't you? You still want to be able to walk behind the wall?

Crispy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sprites clipping into 3D objects
« Reply #2 on: January 27, 2013, 09:57:02 pm »
Yup, absolutely.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprites clipping into 3D objects
« Reply #3 on: January 27, 2013, 10:40:35 pm »
This isn't that simple. You need to decide at what point the character is deemed to be "behind" the wall, and so on.

One approach that springs to mind is -
1. Have a second ortho camera for all the 2d stuff.
2. Detach the player game objects from the sprites themselves.
3. Decide if you want the player to appear in front or behind whatever object is there right now, and move the sprite back/forward appropriately. Deciding this is probably not going to be that complicated if you think about it in 2D. Scale the 2D sprite as it would appear in the 3D camera, but scale it correctly so it appears as though its in the original z position not closer to the camera.

Whatever case you have in that example is a trivial case, think of something a bit more complicated - lets say a grid of walls. The player would have to be in front of some and artficialy behind others.

Crispy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sprites clipping into 3D objects
« Reply #4 on: January 27, 2013, 10:56:35 pm »
I could have a second ortho camera rendering the sprites, but then how would I ever have the sprites appear to be "behind" something? I mean, I could switch between culling layers and z-indices to have them alternate between ortho and perspective, but that wouldn't work if a sprite was sandwiched in between two walls.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprites clipping into 3D objects
« Reply #5 on: January 27, 2013, 11:06:26 pm »
Make sure the second camera doesn't clear depth - you can then use the z position to determine where it draws. You can get it to sandwitch between two walls like that, but you'd have to be careful not to clip one or the other.,..