Sprites Carrying objects and attacking?

Sir Porc here is meant to carry that Club with him all the time, and he is suppose to swing his club when close enough to the player.

What’s the best way of doing this?

The best way I can think now is to make just one object “Sir Porc + Club” = “Sir Porc”, with this object you can do everything related to animations with the club (i.e. basically all… attack, move, stand) :slight_smile: . You could use two objects only when you really need them, for example, if you want Sir Porc to drop the stick when defeated, at the moment he is defeated, create an object Club at Sir Porc hand’s position and set the defeated animation for the pig (in this animation he hasn’t the club)… maybe in the inverse order (set defeated animation, this animation has a hand point, then create the Club at this point)

Another possible way would be to set Sir Porc hand’s position in every frame… in every animation, and set the Club’s grip position in each animation and frame too. Finally “synchronize” the pig and club animations, for example in the attack animation, the pig moves his hand very fast (pig animation), and the club rotates slightly (club animation). You always should change both objects animation together (set stand pig animation, set stand club animation) :neutral_face:

Undoubtedly I choose the first method (maybe somebody has one better), the second one implies a lot of extra-work setting the points and “synchronized” animations. :wink:

I would do that myself, but how would I differentiate when the player’s in contact with the club, and not the Porc?

That, my friend, is the right question… :confused:
As GD doesn’t support multimask-collision detection, maybe you’ll have to set up a lot of points, I’m sorry :frowning:

(As I said before, somebody could have a better solution).

I would check if the “attack with club” animation of porc is playing or not. If playing and the player is in front of porc (compare direction and x position of porc to player) and player is in pixel perfect collision with porc then player get injured. This way basically you can make the illusion of player get injured by the club as it get injured only if it colliding in front of porc and the “attack with club” animation of porc is playing.

In case you want more accurate detection, then no other way around it, as Lizard mentioned porc and the club need to be separated objects. In case the club is in porc’s hands (in terms of detail) the hands/arms with the club need to be separated object. You can create a custom point for porc and set the club/hand position to be at the X,Y position of this point in all frames to follow porc and check collision with the club object.

Above example reminded me of something I’ve seen in The Games Factory beat em up demo game. In addition to checking of animation that example also checked frame range so player wouldn’t be hurt when e.g. enemy is just raising leg to deliver a kick.

More explanations: Let’s say that attack animation has 12 frames. But first 4 frames is just raising club to hit and last 4 are putting club away. So you need to check along with collision and animation if animation frame is between 4-8 (actual attack which can hit player). Fortunately GD provides expressions and conditions for this as well.