Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Entity "Vacuum"

Comments in 'Plugin Development' started by MCPEPIG, Apr 1, 2016.

  1. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    What's the best way to suck entities into a certain position (Like a tornado).
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    That isn't that hard like it sounds.
    You just have to calculate from each player position the right setMotion
    Rough draft:
    $px $py $pz (player)
    $tx $ty $tz (target)
    $tx-$px (if positive) then you have your movement you'll need to apply
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $player->setMotion($target->subtract($player)->normalize()->multiply($speed));
    MCPEPIG, Skullex and Nawaf_Craft1b like this.
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    May you tell us what $target is? Vector3 maybe?
    And i personally hate all these easy to use php functions, i have big projects in C and i have to handle so much on such low level, it's annyoing, what I am trying to point out, you have to learn real programming not writing english.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why would you hate convenient functions? Technology is developed to make things easier, not to make things harder and harder and f*** people's brains. You are trying to make things complicated so as to make yourself sound "professional" and prevent other people from getting the knowledge you have, or be scared of it and then you become the only one in the world who knows programming?
    Or, if you hate easy-to-use PHP functions so much, just don't use them; use the most fundamental functions only and write every function you use yourself.
    Real programming is about thinking, adapting and considering, not about implementing the same thing one billion times because one billion users are using it and everyone has to write the algorithm themselves.
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    The velocity can also be negative, then the player just moves back?
    PEMapModder likes this.
  7. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    May I ask for the usage of normalize() in this function?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In our case, the output of subtract() is a net (position-less) vector representing the line from player to target. Vector3::normalize() will shrink it such that its length shrinks to 1, creating a base vector that is purely directional. Then I multiply the base vector by the speed, so the new vector points to the same direction but with the length as the speed you want.
    MyNameIsTriXz likes this.
  9. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Oh shit
  10. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I just wanted to say that if you're good in php, you will be suprised that you need 1000 lines in C for a 200 lines php programm. And i personally like php, and if i sit on my C project, i sometimes rage out and say I WANT FOREACH HERE. Actually i like these php functions. But it may be getting slow. If you realy want a fast programm you need to code a little bit more low-level. Languages like brainfuck, of course make no sense, but they may be even faster then assembly.
  11. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Just noticed I got way too much offtopic, sorry
  12. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Did you see that (if positive)???
    That was a rough draft, of course you need to do sth else with negative coordinates
    Last edited: Apr 1, 2016
    Legoboy0215 likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Library functions != slow language
    You may need to implement those functions in C++ yourself (I prefer to say C++ even though it is C, simply because C is one letter only and easily gets ambiguous). But if it was originally implemented in the standard library, it would not make things faster.

    You are comparing at different criteria. The PHP language itself is slow because it is a parsed language without compiling to native code or running on a virtual machine [citation needed]. And the PHP language provides a wide range of builtin functions, but this has no relationship with what you said about the language itself being slow. Look at Java. It is almost as fast as C++ nowadays, but it still has a good broad library that does many things.
    Back to your original point, you were saying that PHP is not real programming because you just have to write English, which is very wrong. It just provides a lot of builtin functions such that you don't even need to think in most cases, making it such that some people go to interview but not even know how to get the average of numbers in an array [1].

    References:
    [1] http://sijinjoseph.com/programmer-competency-matrix/ "Unable to find the average of numbers in an array (It’s hard to believe but I’ve interviewed such candidates)"

Share This Page

Advertisement