[rigidbody2d] how to add force to Z axe

Hello everyone,

is there anyway to make a 2d object move in the Z axe using rigidbody2d ? (i don’t want to use transform)

Edit:
i want to use rigidbody2d instead of the classic one is because i need to use circleCollider2D and polygonCollider

btw, what am trying to do is something like this
alt text

the blue circle is the player, it is suppose to be controlled with the mobile device accelerometer and i already done that, now what i need is to simply check if the blue circle is standing on top of one of the gray platform circles and if not it should fall and it’s game over. So far the only solution that i could think of is to flip everything including the camera, make the player fall within the Y axis, and make it move with Transform.translate by assigning the Y value of the accelerometer to the Z axis of the transform position, but i thought maybe there is a simpler way to do that. of course 3D is not an option unless there is a way to create colliders like polygon and edge colliders does.

Thank you

1 Answer

1

Z axis? There is no Z axis in 2D games. Z axis will basically have it go behind other objects.

I.e: Object 1 z axis is at 0. Object 2 z axis is at 1. Object 2 will be in front of object 1.

If you want the player to fall, or at least give the illusion. You should decrease the size of the player when it’s out of bounds by a steady amount for a certain amount of time. Then restart.

my problem is how to detect the "out of bound" and not the falling illusion (i think i'll just make it explode when its outside the platform) thanks

Make triggers. And use the following of course, change it to suit your needs void OnTriggerEnter2D(Collider2D col) { if(col.gameObject.tag == "your death area tag") { // shrink the player to give the illusion of falling // delay // restart } } DISCLAIMER: Not tested

i thought about that too, but how can i make the colliders of the death area ? i thought about create an edge collider around the platform circles but as you can see when two circles are next to each other like that, the player will be forced to die even when it shouldn't, so in this case the only thing that could work is to create some sort of door between the two circles but am still looking for a simpler solution

also i want the player to be effected by what's happening with the platforms, for example if the platform is moving, the player should move alone with it, parenting can fix this but i'd rather use physics to do it