Bouncing snowballs

Discussion in 'Plugin Development' started by THEREDBARON24, Apr 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    THEREDBARON24

    Well I was thinking that it would be really interesting to have bouncy snowballs or eggs for a game of sorts, however, I am not sure what I am doing wrong This is the code that I have (and it is registered and "working")
    Code:java
    1. public void onOtherHit(ProjectileHitEvent event){
    2. if(event.getEntity().getType() == EntityType.SNOWBALL){
    3. event.getEntity().setBounce(true);
    4. }
    5. }

    Any help is appreciated!
     
  2. Offline

    Slikey

    Maybe, you need to reset the velocity?
     
  3. Offline

    Zwander

    Is the snowball 'shattering' or is it just sticking into the block?


    doesBounce doesnt do much:
    from: https://forums.bukkit.org/threads/bouncing-snowballs.30661/
     
  4. Offline

    stink123456

    I never heard of the setbounce method but if you learned mathematics you could make on your self, just get the angle the object is flying on and mirror it when it hits the ground, then change the velocity to that direction. Note that you could add ground resistance by removining some of the velocity
     
  5. Offline

    Slikey

    Just an addition: To mirror a vector on from the ground, just invert the Y-Coordinate.
    vector.setY(-vector.getY());
     
  6. Offline

    stink123456

    Slikey you are completly right, when the entity hits the ground just set the y vector of the entity to the inverse value :) Logic minds, we should have more of those instead of people like me finding the most complicated solution there is...
     
  7. Offline

    Slikey

    stink123456 Maths are illogical somethimes ;) No problem.. :D

    @stink123456Believe me.. If I do my effects, there are 100 ways to do it, but I always do the most complicated first.. But this is not the topic..^^ Back to Topic. ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  8. Offline

    stink123456

    Haha i guess we have the same mindset then, should we consider this thread as closed? Only the ball doesnt bounce of walls this way sadly :( so you would first need to check what side you hit, then reverse that axis. And it also might be smart to cancel the hit event of the snowball. Good luck!
     
  9. Offline

    THEREDBARON24

    well thx for the help :p Zwander The ball is shattering and as far as I am aware the only other option is using math, so if you have any ideas, let me know!
     
  10. Offline

    Zwander

    So i think the solution iiiisssss (drum roll)

    Spawn another snowball where the previous one landed and set its velocity vectors accordingly. ie: Take the old snowballs vectors, detect which axis' it collided on and -ve them.
     
  11. Offline

    THEREDBARON24

    Makes sense, unfortunate that the method is not usable (apparently)
     
  12. Offline

    Zwander

    THEREDBARON24
    EDIT: I is confuse..
    What do you mean 'the method'?
     
  13. Offline

    Slikey

    Aaaand here is the proof, that doesBounce() does nothing.
    AbstractProjectile
    https://github.com/Bukkit/CraftBukk...it/craftbukkit/entity/AbstractProjectile.java
    and neigher the getter nor the variable is called from this class:
    CraftProjectile
    https://github.com/Bukkit/CraftBukk...ukkit/craftbukkit/entity/CraftProjectile.java
    nor this class uses it.. which is at the end of the inheritance chain..
    CraftSnowball
    https://github.com/Bukkit/CraftBukk.../bukkit/craftbukkit/entity/CraftSnowball.java
     
  14. Offline

    THEREDBARON24

    hmm, well isn't that great? Also, how would i go about getting the block face that the projectile hit? Also I meant the doesBounce and SetBounce methods.

    Zwander Slikey Figured I should tag you for easier notification :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  15. Offline

    Slikey

    THEREDBARON24 Yeah. Tagging is awesome. ;) But I think that you need to work on that for yourself.. I could help you through the theory, but coding this is too time intense.. I need the time to work on my EffectLib. Sorry..
     
  16. Offline

    Zwander

    @THEREDBARON24

    Yay for tahgs! The face that the snowball hit will be whichever side it is closest to. Thus you can get the value of each dimension (x,y,z), modulo operator it by 1 to get the decimal part (9001.75%1=.75), subtract 0.5 and Math.abs (makes positive) to get the distance from the center. You can then Math.max(x dist, y dist, z dist) to find the highest one, then check each value, if it equals the max,, times the corresponding vector by -1.

    Code:java
    1. double x=location.getX();
    2. double y=location.getX();
    3. double z=location.getX();
    4. //x=178.8
    5. //y=234.1
    6. //z=958.34
    7. double x2=(x%1);
    8. double y2=(x%1);
    9. double z2=(x%1);
    10. //x2=0.8
    11. //y2=0.1
    12. //z2=0.34
    13. double x3=x2-0.5;
    14. double y3=y2-0.5;
    15. double y3=y2-0.5;
    16. //x3=0.3
    17. //y3=-0.4
    18. //z3=-1.6
    19. double x4=Math.abs(x3);
    20. double y4=Math.abs(y3);
    21. double z4=Math.abs(z3);
    22. double maxValue=Math.max(x4,y4,z4);
    23. //maxValue=0.4
    24. if (x4==maxValue){
    25. //flip x vecor
    26. }
    27. if (y4==maxValue){
    28. //flip y vecor
    29. }
    30. if (z4==maxValue){
    31. //flip z vecor
    32. }
    33. //y vector is flipped


    EDIT: Awks I meant to write pseudo code but I ended up writing actual code
     
  17. Offline

    blablubbabc

    Here you go: bouncing snowballs. This also takes special blocks into account, like water and half blocks. Only 'issue' (which you probably won't notice) are stair blocks: they only bounce 'properly' from one side (from sidewards or front, I am not sure right now).
    Original idea from eyalzh's bouncing arrows plugin: https://github.com/eyalzh/bouncingarrows
     
  18. Offline

    THEREDBARON24

    Thanks to both of you. I will see how this goes.
     
Thread Status:
Not open for further replies.

Share This Page