I’m working on my first Unity project, the intention is to create a top-down 2D (sprite-based) game.
So far, I’ve been using the Rigidbody2D and Collider2D components.
My problem is this:
The Physics 2D seems to be only made for side-scrollers, if I use the 2D physics, It can only use the X and Y axis.
So, my current North/South axis is Y, my East/West axis is X, while my Up/Down axis is Z.
This messes up the physics; gravity on Physics 2D is only in X or Y axis, so it can’t be used. Velocities work OK but things float on for ever since there’s no gravity or friction.
Have anyone tried making a top-down game with the new Physics 2D?
The Physics 2D components are seemingly impossible to use on X/Z axis.
I’m not sure but I think there is a option in settings that lets you select the “direction” of gravity. So for your case you would select Z since you move along X and Y.
EDIT:
Yes there is. Go to Edit–>Project Settings–>Physics 2D . In Inspector you can set X to 0, and Y to 0 so your characters don’t fall along Y axis.
You can use 3D physics with sprites if you really need 3D movement; otherwise just say that Y is forward and turn off gravity. To use friction, increase the linear drag.
I started by using AddForce to move my character but it didn’t work very well with the physics settings I had on my rigidbody.
I’m using pretty much the same transform as your first example right now. For character movement I’m not too concerned with physics yet, what’s more important is slow-moving projectiles (thrown, rockets, debris etc).
Adding some linear drag might be what I need - testing will commence!
Well that’s easy to answer.
Your framerate is higher than, or slightly desynchronised from your physics update rate, so in between physics update steps your object is moving tiny increments into the wall, and then the interpenetration is being solved when the physics engine gets around to looking at things.
I’m not sure exactly how to fix it besides using fixedUpdate though. To be honest i don’t know why Eric would advise you not to use it. Movement is inherently a physics action and i think that sort of thing should always be done in physics, unless the object is purely visual (eg, a particle, or background scenery)
And i just now realised this thread is a year old, and i got here through google. I’m sorry T_T
Because FixedUpdate is not in sync with the framerate, so movement looks stuttery. You can fix that if you’re using physics forces by using interpolation or extrapolation, but if you’re moving manually, you need to use Update and not FixedUpdate.
You simply need to increase the “drag” value of your rigid body to prevent it from sliding around forever.
Top-down games using 2D physics require a different approach. Since 2D physics only work with the X and Y axis. You need to essentially build your top-down game on its side. Rotating everything to orientate with the 2D physics. Just forget that the Z axis exists. If you really want to use the X, Y, and Z axis, then you’ll need to use real 3D physics with sprites instead.
There is an excellent video on the basics of a top-down game over on the Live Training Archive
I’m in a similar situation where I need to set the gravity in X and Y directions to zero in Physics2D settings. But I still need to do calculations using a gravity constant in the Z direction so it’s a shame the Z component isn’t available as a placeholder. Now I need to make my own public variable for gravity - attached to each car I guess. Or is there a place for global constants somewhere in the project where I could store this?
@biletubes Just use 3D physics like Eric said. Then align your objects to match the 3D rather than 2D orientation. You can also change the gravity force and direction for both 3D and 2D physics under Edit > Project Settings > Physics/2D: