0
\$\begingroup\$

I've done some simple tile based collision: Move character, look up the tiles moved into, and if solid, push them back out. I move on each axis independently, because this gets them to eject properly. My game uses 2D Sprites, but its physics is 3D, so this includes the X, Y, and Z axes.

I don't want every tile to feel like a brick of lead. I want walking into a bush to feel springy. I want to feel a bit of sag when walking on snow. I want running up a steep slope to feel harder than running down a decline. I want for some tiles to bounce you off like trampolines, and for others, to absorb the full impact so that you stop in your tracks.

All of this works very much against the "hard thing pushes out" design I have so far. It occurs to me to that with slopes, it might not to work to push against each axis individually. Now that I think about it, how do I handle collisions with more than one tile at once if they have different softness properties?

How does one accomplish this sort of thing using tiles-based (or in my case, more accurately, blocked-based) collision?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

You mentioned a list of goals you want to achieve. In my opinion, they cannot be achieved using a single out-of-the-box way. You can unify them by wrapping the existing physics engine, But each effect needs to be implemented separately.

I don't want every tile to feel like a brick of lead.

Unfortunately, most modern general-purpose physics engines use Rigid_body to describe physical objects. This is an ideal model for convenient calculations. In the real world, the force generated by the collision between objects comes from their deformation, while the rigid body collision ignores the deformation process and directly performs a Elastic_collision(or a Inelastic collision). So by default they just feel like bricks.

I want walking into a bush to feel springy. I want to feel a bit of sag when walking on snow.

You can implement your own spring components using Hooke's law. It applies opposite forces to the connected two objects every frame. The magnitude of this force depends on the compression of the spring. When the elasticity coefficient is high, you get a bush, and when the elasticity coefficient is small, you get a snow field.

I want running up a steep slope to feel harder than running down a decline.

Add a horizontal force when running, and the component perpendicular to the incline is automatically canceled when going uphill. Or detect the angle of the incline and change the running speed according to it, solve this problem at the business layer.

I want for some tiles to bounce you off like trampolines, and for others, to absorb the full impact so that you stop in your tracks.

You can artificially specify the energy loss factor(or Coefficient of restitution) for inelastic collisions. It specifies how much energy will be converted from kinetic energy to other energy in a collision. (In the physics engine they just disappear). Some engines include it in physical materials. You can implement it yourself, or find out if the physics engine you are using has this feature.

\$\endgroup\$

You must log in to answer this question.

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