I remember your other post(s). Here’s the same info again:
Unity 2D physics ONLY takes place in a 2D plane in the X/Y, and Z is always zero.
ONLY 2D versions of physics classes (such as colliders and rigidbody and joints) may be used with 2D.
By “used” with I mean “appear on the same GameObject and interoperate via the Physics2D system.”
That’s all there is to it.
So if you contemplate being fancy with 3D going on around your 2D physics simulator, that’s great.
Just know that absolutely nothing about the 2D physics system is going to change or care:
100% of EVERYTHING in 2D will ALWAYS be in the X/Y plane at Z == 0.
If YOU want to move data from the 2D simulated objects to the 3D world, GREAT! Do it. Moving 3D info back to 2D? GREAT! Just know that Z is always gonna be lopped off and be zero.
For instance, I made a game called TankCombat2D and a game called TankCombat3D.
They BOTH operate in 2D, but I am copying data from 2D to 3D for my 3D version.
It is identical game logic. The 2D game is running in the 3D world and EVERYTHING is invisible, and I am copying the 2D coordinates and projecting them in 3D.
Here’s the 2D → 3D projection code:
namespace TankCombat3D
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TankCombat2D;
public partial class TankCombat2D_Visualize3D : MonoBehaviour
{
const float OurCellSize = 2.0f;
// proxy transform to turn the 2D world into something that can be seen in 3D
public static Vector3 TransformPosition( Vector3 position2D)
{
// DO NOT USE source.z - it is meaningless
float x = position2D.x;
float z = position2D.y;
const float CellSize = 2.56f;
x /= CellSize;
z /= CellSize;
x *= OurCellSize;
z *= OurCellSize;
var position = new Vector3(
x,
100,
z);
return position;
}
// proxy transform to map euler.z in 2D into euler.y in 3D
public static float TransformZRotation( float angle)
{
return -angle;
}
}
}
You can see it yourself at: Kurt Arcade by Kurt Dekker