How do I knockback with physics?

0 favourites
  • 4 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Hey guys, so, my project is room based, each room has colisors (red).

    The enemies are moving using physics, the only way that I found that moves the enemies like vampire survivors, without overlapping them.

    When the player attacks, if he attacks an enemy, the enemy got a knockback effect, where now he move at angle to a specific force*dt like the image.

    The problem is that I could not find a way to prevent enemies from overlapping the room colisors, even changing the move to angle for apply impulse.. Sometimes it works, sometimes the enemy just overlaps and get stuck there..

    Can anyone help me?

    How the Orc knockback works right now:

    Is overlapping attack_colisor -> trigger once -> Orc.Timer.Knockback Start

    Is Orc.Timer.Knockback running -> Set Orc.Physics.velocity = 0, Move Orc at Angle: angle(player.X,player.Y,Self.X,Self.Y) distance: playerKnockbackStrength*dt

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't think it's a good idea to use Physics in this type of game. If the sole purpose of it is preventing enemies from overlapping, you should look for a different approach.

    If you are using Physics, you should avoid moving or rotating the objects with non-physics actions or behaviors, because this breaks physics calculations. You should only use Physics actions like Apply Force, Set Velocity etc. For the knockback effect I suggest applying impulse or setting physics velocity.

  • You probably want to work out a steering/flocking system instead of using physics.

    The most simple one is to use two bullet behaviors on your sprite, and add your sprite to a family.

    The first bullet behavior is a constant speed, 0 acceleration, with angle set towards your target.

    The second bullet behavior is a 0 speed, small acceleration, disabled by default.

    On sprite overlap family, set bullet2 to enabled, and set the angle to angle(family.x,family.y,sprite.x,sprite.y)

    Then on sprite not overlapping family, set bullet2 speed back to 0 and disable.

    You can improve this by adjusting the (repulsion) acceleration based on distance, rather than simply overlapping.

  • You probably want to work out a steering/flocking system instead of using physics.

    The most simple one is to use two bullet behaviors on your sprite, and add your sprite to a family.

    The first bullet behavior is a constant speed, 0 acceleration, with angle set towards your target.

    The second bullet behavior is a 0 speed, small acceleration, disabled by default.

    On sprite overlap family, set bullet2 to enabled, and set the angle to angle(family.x,family.y,sprite.x,sprite.y)

    Then on sprite not overlapping family, set bullet2 speed back to 0 and disable.

    You can improve this by adjusting the (repulsion) acceleration based on distance, rather than simply overlapping.

    This just got me.. 2 bullets.. I didnt know that was possible to have 2 bullets behaviors on the same object.. Im gonna try it, thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)