#player's head movement

1 messages · Page 1 of 1 (latest)

proud shuttle
#

what video!??!?!?!

brave pilot
#

Either use Player#sendHurtAnimation(float) method or send a damage animation (screen shake) packet.

#

You can, but it will be noticeable and not as smooth as screen shaking from getting damage.

#

Hmm... fair point. Add a constant to their pitch then.

#

No. A fixed number.

#

Ugh... Just add some number to pitch you feel like is the best to simulate a gun recoil.

#

In addition, there's some code from Gunshell plugin:

public void recoil(Player player, float pitchIncrement, double knockback) {
    Location location = player.getLocation();
    if (pitchIncrement > 0) {
        float pitch = location.getPitch();
        location.setPitch(pitch - pitchIncrement);

        // Use a cause other than PLUGIN or COMMAND because essentials sucks lol.
        Vector playerVelocity = player.getVelocity();
        player.teleport(location, PlayerTeleportEvent.TeleportCause.UNKNOWN);
        player.setVelocity(playerVelocity);
    }

    KnockbackUtils.applySelfKnockback(player, knockback);
}```
proper vine
brave pilot
#

It was just to show how it's done in a plugin. I am perfectly aware of that.

#

Your code can be simplified to:

    subtract 1 from player's pitch
    wait 1 tick```
proper vine
brave pilot
#

Yes, but at the cost of recoil's duration.

#

It was just an example.

proper vine
#

no i meant it for improvement for the guy that needs this not for your code, which is totally fine

brave pilot
#

This is because you can't delay code execution by less than 1 tick. This is a limitation of your solution.