In my project I'm making a game like Super Mario Bros 2 where you can pick up and throw enemies. I've figured out the picking up part, but I'm trying to think how to create a throwing function.

I wasn't sure if you can apply forces to CharacterBody2D because I know stuff like "apply_impulse" is only for RigidBody2Ds, but people say you should use CharacterBody2D for enemies.

Any idea of how I could throw a CharacterBody2D forward? (and then naturally they'd fall downward from the effects of gravity) or should I try different solutions, like making the enemy a rigid body?

Kind of like this:

  • Jesusemora replied to this.
  • NJL64 but people say you should use CharacterBody2D for enemies.

    who said that?

    NJL64 throw a CharacterBody2D forward

    CharacterBodies are KINEMATIC, they are moved by code, not by physics. you can make it move in whatever direction you want.
    You need to implement state machines in your enemies and characters.

    But in this case you can also replace the enemy with a physics object, and after a timer, replace the physics object again by an enemy.
    you do this by first instantiating the other object and adding it as a parallel node with add_sibling(), and then calling queue_free() to delete self.
    unless the enemy need to keep some kind of score, which is not common in these types of games.

    NJL64 but people say you should use CharacterBody2D for enemies.

    who said that?

    NJL64 throw a CharacterBody2D forward

    CharacterBodies are KINEMATIC, they are moved by code, not by physics. you can make it move in whatever direction you want.
    You need to implement state machines in your enemies and characters.

    But in this case you can also replace the enemy with a physics object, and after a timer, replace the physics object again by an enemy.
    you do this by first instantiating the other object and adding it as a parallel node with add_sibling(), and then calling queue_free() to delete self.
    unless the enemy need to keep some kind of score, which is not common in these types of games.

      Jesusemora Thank you for the advice. I have state machines for my characters and enemies and know physics are implemented differently with kinematic and rigid bodies, but I'm still a little new and just wanted to make sure I was making the right call or just know what I'm doing, so thank you because this is a clearer vision of a method I was thinking of going for.

      I'm gonna keep this suggestion in mind when trying to work it out. Either way, thank you for helping me talk it out with potential solutions and a clearer understanding of how to use kinematic bodies/rigid bodies. I'll let you know if I get good results. 🙂