Play Knock back animation but don't damage.

Discussion in 'Plugin Development' started by damo1995, May 20, 2012.

Thread Status:
Not open for further replies.
  1. Hello all.

    As the topic above says im wanting to play the knock back effect on somebody like from a knock back sword but not actuly damage the player. Is this possible? If not is it possible to just knock them back at all im not too bothered about not removing the damage but if it can be it would be good.


    Thanks in advanced.

    Damo.
     
  2. Offline

    keelar

    Yes, it is possible. You'll have to cancel the damage event(obviously) and then I think you'll have to mess with the players(victim) velocity using a vector.

    I'm pretty nooby when it comes to things like this also, so I'm sorry I couldn't directly help you with an example, but I know it can be done if you just check the direction the attacker is looking and modifying the victims velocity accordingly. Sorry about the lack of detail, but nobody else has responded so I thought some help is better than none. Just mess around with the velocity of the victim and I'm sure you'll be able figure something out.
     
  3. Offline

    Njol

    If you're doing this in a damage event, you can heal the player by 0.5 hearts and set the event's damage to 0.5 hearts, so that the animation plays but the player doesn't lose any health. If the player is already at full health you can use a delayed task with a delay of 0 ticks which heals the player by 0.5 hearts.
    Otherwise you can always play the HURT animation (player.playEffect(EntityEffect.HURT)) and optionally launch the player a little bit in a random direction.
     
  4. keelar Thanks for the response i guessed it would be something to do with cancelling the damage event

    and Njol im wanting to do it on a command not the actual damage event or entitydamagebyentity. SO the best way of doing this would be to set the players velocity?

    Thanks.
     
  5. Offline

    Njol

    The normal danage thrusts the damaged player a bit away from the damage source, e.g. a mob or another player. But since you don't have a souce you can either launch the player straight up into the air a bit or in a random direction. You can do it e.g. like this:
    Code:
    double max = 0.2; // maximum velocity offset
    double x = max*(2*Math.rand() - 1);
    double z = max*(2*Math.rand() - 1);
    double y = max*(0.5*Math.rand() + 0.5);// at least 0.5*max
    player.setVelocity(player.getVelocity().add(new Vector(x, y, z)));
    player.playEffect(EntityEffect.HURT));
     
Thread Status:
Not open for further replies.

Share This Page