1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Setting player gravity does nothing

Discussion in 'Development' started by CortexPE, Aug 5, 2018.

  1. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    Ok, before you start telling me that this is impossible lemme tell you what I've tried:

    I've tried setting a custom Player Class on PlayerCreationEvent with a CustomPlayer::setGravity() method to be able access the protected Living class' gravity instance variable (instead of reflection, which also doesn't work)

    It worked ONE LUCKY TIME (not the first time) where I'm stuck mid air and doesn't fall down but I can still fly up.
    but, all the other time doesn't work and does nothing.

    I dumped the gravity property's value and it is the correct value I set it as (0.01)

    I also tried making a separate entity to test it there and it seems to work for the entity... but not for the player.

    And ideas why?

    What's my goal and why I'm changing the gravity you might ask, I'm trying to slow down player fall... instead of doing it the hacky and janky way of using a custom entity that has its gravity set to 0.01 that also falls down then teleporting the player on every update, I want to use the built-in player's physics because that'd be a lot smoother and the player would be able to move unlike when teleporting every update.
     
    TeraCube and Kyd like this.
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    Player movement is entirely client-dependent. Those gravity values are only used for server-sided movement of mobs, which is disabled for players.
     
    CortexPE likes this.
  3. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You could consider instead using negative levitation for a slow fall, but I think PM doesn't like negative effects so much when serialized to NBT.
     
    CortexPE likes this.
  4. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    Levitation hasn't been implemented though
     
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    If you don't care too much about anticheat you should be fine just doing
    PHP:
    $effect = new Effect(25"%potion.levitation"00/* whatever colour you desire*/)->setDuration(100)->setAmplifier(-/*some negative number*/);
    $effect->add($player);
     
  6. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    That actually worked... It should be fine though since I'm only going to use it for like 20-30 seconds...
    then remove it afterwards

    (Effect ID 25 is poison lol xD idk if you used that on purpose or as an example lmao)
     
    Sandertv likes this.
  7. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    it did puke out bit shifting errors on the first try though

    nevermind, this only applies to poison
     
    Last edited: Aug 7, 2018
  8. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    it's registered, it just isn't applied server-side. The floating is done by the client.
     
  9. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    would it look the same and be in-sync on other clients?
     
  10. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    It's entirely dependent on the player movement, so to other players it'll look fine, as long as you don't have any anti-cheat interfering.
     
    CortexPE likes this.
  11. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Sorry, code I provided was invalid too, seems I was inspecting an old version of the effect class.
     
  12. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    Actually I thought it was pseudocode so I anticipated that I needed to rewrite it properly xD
     
    Sandertv likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.