4
\$\begingroup\$

First off, I am making a game similar to SSB, which relies heavily on physics, even though it is a sidescroller. I am currently using Unity.

In Unity there are "character controllers" which are used for characters that move, but they don't interact with other physics objects. There are also rigid bodies, which are completely realistic physics components. I can't figure out how to use rigid bodies for human/humanoid characters. Here's some questions I have:

  • How should I move the character? Applying forces is not the way to do it, right? Would you set velocities or pixel-by-pixel movement, perhaps?

  • What kind of collider should I use? I've been using a capsule collider. But is that the best way?

  • How do you make him not fall down!? After some experimenting, I discovered that the character falls over (from applying force/velocity and from the capsule collider tipping it over). Would you constrain the rotation in the Z-axis?

  • What do you do when he gets hit? If you've ever played SSBB you'll be familiar with this topic. I'm thinking that applying a force would be best in this condition? If you did constrain the rotation, would you un-constrain it?

    Ike punching link

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Mostly answered by Good 2D Platformer Physics. The answer seems to be: it's really ugly trying to get a physics engine to cooperate with something with requirements as strict as a platformer. You can work with a physics engine, but it's going to be tricky enough you probably shouldn't even want to. Write a simple physics engine that addresses your specific needs. \$\endgroup\$ Oct 16, 2011 at 4:50

1 Answer 1

3
\$\begingroup\$

How should I move the character? Applying forces is not the way to do it, right? Would you set velocities or pixel-by-pixel movement, perhaps?

Apply linear (and possible angular) impulse. The object retains velocity and imparts force to other objects on impact.

What kind of collider should I use? I've been using a capsule collider. But is that the best way?

The capsule collider is what you get with Unity, because it works well for most sorts of games. You could either continue to use it with adaptation (to the FirstPersonController script), or construct your character entirely out of bounding cylinders or bounding boxes (limbs, body, head etc.). The latter won't be as easy, but for a fighting game you'll have more accurate combat. I'm not sure this is really necessary as your game is actually 2D anyway, so benefits from this will be less than if your game were actual 3D.

How do you make him not fall down!? After some experimenting, I discovered that the character falls over (from applying force/velocity and from the capsule collider tipping it over). Would you constrain the rotation in the Z-axis?

Considering you're using rigid bodies, you're going to have to find some way to constrain, yes. It's either that or you switch between kinematic and rigid bodies at given times. The problem with the latter is you still need to know when the collision between your fist and the enemy's face occurs. So better to stick with rigid body physics throughout.

What do you do when he gets hit? If you've ever played SSBB you'll be familiar with this topic. I'm thinking that applying a force would be best in this condition? If you did constrain the rotation, would you un-constrain it?

Yes, apply a force; this could be as you switch the character back to rigid body mode (possibly based on where the character was hit, and for how much). In that case, when the character begins to recover, turn kinematics back on so he can stand up again.


NB What I've said above about using a mixture of kinematic forces and dynamic ones is one way to do it, and in some ways the easiest. However you can also purely use impulses with rigid bodies to control things. In my experience, this can be less than simple, so caveat emptor.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .