0
\$\begingroup\$

I have iOS game where I have a bouncing character. Everything is being handled by box2d. The problem is when the character hits a wall of another character it's velocity changes, but I don't want this. I need the velocity to stay constant even after collisions.

I was thinking the only way to do this was to keep setting the velocity after each collision unless there's another way to do this that I'm not aware of?

\$\endgroup\$
6
  • \$\begingroup\$ Show us your code. \$\endgroup\$
    – Shroeder
    Oct 30, 2014 at 15:39
  • \$\begingroup\$ I just need to know generally if there's an easy way to make it happen or not. \$\endgroup\$
    – Phil
    Oct 30, 2014 at 15:53
  • \$\begingroup\$ His velocity changes direction and speed or just direction? \$\endgroup\$
    – Shroeder
    Oct 30, 2014 at 19:06
  • \$\begingroup\$ I am not sure I understand, you want the velocity to stay the same when the character hits a wall? i.e you want the character to pass through walls? \$\endgroup\$
    – AturSams
    Nov 2, 2014 at 6:05
  • \$\begingroup\$ @NauticalMile It is not a duplicate (I think), because the question you mentioned dealt with a flying body and this one with a bouncing body. In this first case I'd use a kinematic body if understood the question correctly and in this one I'd consider increasing the mass dramatically and then applying a tiny force to re-stabilize speed. \$\endgroup\$
    – AturSams
    Nov 2, 2014 at 6:14

1 Answer 1

0
\$\begingroup\$

If you want to maintain the velocity of a body (and have it ignore collisions), just set the body type using the b2body::setType function:

mybody.setType(b2_kinematicBody);

Alternatively, the b2BodyType can be assigned to the b2BodyDef before the body is created using the b2BodyDef::type public attribute:

mybodydef.type = b2_kinematicBody;

All kinematic bodies will move with constant velocity, completely ignoring collisions.

\$\endgroup\$

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