1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

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

Solved how to make a rebound ? (advenced math)

Discussion in 'Skript' started by aeim, Nov 19, 2017.

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

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    Hi everyone (I'm FR, sorry for my english)! I have my own projectile trajectory system based on the reality.
    This cool system allows me to predict the trajectory of my projectile even before firing (in 1 tick)!

    How to calculate a projectile rebound against a block ?
    (I'm talking about a projectile but it's an armorstand and not an arrow)

    You can have your own technique for this problem.
    Here is what I propose:

    INFO:
    With my current code the location of impact is ({_x}, {_y}, {_z});
    The previous location is ({_x.old}, {_y.old}, {_z.old});
    The location of the center of the block on which the projectile must bounce ({_bx}, {_by}, {_bz})

    my idea :
    1) We consider the block as a sphere and not a cube, we draw a vector between the point of impact and the current position.
    2) A reflection effect of the previous location with respect to the vector is applied (vector which will be positioned from the point of impact)
    Info: The old position, the point of impact and the vector are necessarily on the SAME plane which makes the operation possible.
    3) A vector is drawn between the point of impact and the mirror point.
    4) We recover the yaw and pitch of this vector with "vector yaw of %vector%"
    5) It's over! The rest of my code takes care of considering the point of impact as if it is a new shot = D

    This method is like folding a sheet of paper
    [​IMG]

    To help I have a lot of addon that can be used to solve this problem (Umbaska is removed voluntarily and I do not want to use it anymore).

    [​IMG]

    Help link :
    https://skripthub.net/docs/?search=id:1345 (I need this but it seem to not result the correct location)
    https://github.com/bi0qaw/Vectors-Skript (A secret addon ^^)

    The part to modify is between the "================="
    The rest of the code works very well

    Code (Skript):
    1. on script load:
    2.   import "java.lang.System"
    3.   import "java.lang.Math"
    4.  
    5. command /rr <number> <number>:             #this is just a test
    6.     trigger:
    7.         set {_x} to arg-1
    8.         set {_z} to arg-2
    9.         set {_pi} to {Math}.PI!
    10.         set {_atan2} to {Math}.atan2({_x} and {_z})
    11.         set {_yaw} to {_atan2}*180/{_pi}
    12.         broadcast "%{_yaw}% %vector yaw of vector {_x}, 0, {_z}%"   #2 method to get yaw, first between [-180,180] , second between [0,360]
    13.        
    14.        
    15. function Shoot(shooter: player, type: string, force: number, predict: boolean):
    16.     set {_pi} to {Math}.PI!
    17.     set {_x0} to x-location of {_shooter}
    18.     set {_y0} to y-location of {_shooter}
    19.     set {_z0} to z-location of {_shooter}
    20.     set {_pitch} to pitch of {_shooter}*-1  #The rotation of player
    21.     set {_yaw} to yaw of {_shooter}*-1
    22.     set {_v0} to 17.7*{_force}              #17.7 is my own chosen number randomly for the velocity
    23.     set {_cosPitch} to cos ({_pitch}*3.14/180)
    24.     set {_cosx} to (sin ({_yaw}*3.14/180) )* {_cosPitch}
    25.     set {_cosz} to (cos ({_yaw}*3.14/180) )* {_cosPitch}
    26.     set {_t} to 0
    27.    
    28.     set {_RotPitch} to {_pitch}             #The rotation of projectile
    29.     set {_RotYaw} to {_yaw}
    30.    
    31.    
    32.     if {_predict} is false:
    33.         set {_ID} to "Shoot_%{_shooter}%_%{game.timer}%"
    34.         run {_shooter} command "/summon ArmorStand %x-location of {_shooter}% %y-location of {_shooter}% %z-location of {_shooter}% {CustomName:""%{_ID}%"",Tags:[""Shoot"",""Shoot_%{_shooter}%""],NoGravity:1b,Small:1b,Marker:1b,Invisible:1,Invulnerable:0,DisabledSlots:2039583}" as op
    35.         loop all armor stands:
    36.             loop-entity's name is "%{_ID}%"
    37.             set {_entity} to loop-entity    #not used for now
    38.             execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /playsound minecraft:entity.irongolem.attack master @a %{_x0}% %{_y0}% %{_z0}% 1 1"
    39.             if "%{player::*}%" contain "%{_shooter}%":
    40.                 execute console command "/mycmd add %{_shooter}% stats.use.%{_type}% 1"
    41.             if "%{_type}%" is "fragmentation":
    42.                 set helmet of loop-entity to yellow dye
    43.                 set {_color} to "0 1 0"
    44.             if "%{_type}%" is "retardement":
    45.                 set helmet of loop-entity to red dye
    46.                 set {_color} to "0 0 0"
    47.             if "%{_type}%" is "chimique":
    48.                 set helmet of loop-entity to light green dye
    49.                 set {_color} to "0.27 0.77 0.18"
    50.             if "%{_type}%" is "flame":
    51.                 set helmet of loop-entity to orange dye
    52.                 set {_color} to "1 0.5 0.1"
    53.             if "%{_type}%" is "implosion":
    54.                 set helmet of loop-entity to light blue dye
    55.                 set {_color} to "0.1 0.9 1"
    56.             if {_color} is not set:
    57.                 set {_color} to "1 1 1"
    58.                
    59.     loop 900 times:
    60.         set {_xt} to {_v0}* {_cosx}         #I put this here cause of the speed {_v0} can be modified (exemple: in water)
    61.         set {_zt} to {_v0}* {_cosz}
    62.         set {_x} to {_x0}+{_xt}*{_t}
    63.         set {_y} to (-12/2*{_t}^2) +{_v0}*{_t}*sin ({_Pitch}*3.14/180) +1.52 +{_y0}     #+1.52 is for eye's position
    64.         set {_z} to {_z0}+{_zt}*{_t}
    65.        
    66.         set {_vectorx} to {_x} - {_x.old}           #I prefer use %vector% only if a complex math operation is more easy with an addon
    67.         set {_vectory} to {_y} - {_y.old}
    68.         set {_vectorz} to {_z} - {_z.old}
    69.         set {_norme} to sqrt ( {_vectorx}^2 + {_vectory}^2 + {_vectorz}^2 )
    70.         set {_vectordirx} to {_vectorx} / {_norme}
    71.         set {_vectordiry} to {_vectory} / {_norme}
    72.         set {_vectordirz} to {_vectorz} / {_norme}
    73.        
    74.  
    75.         set {_RotPitch} to -57.2958* arc sin ({_vectordiry})
    76.         set {_atan2} to {Math}.atan2({_vectordirx} and {_vectordirz})
    77.         set {_RotYaw} to {_atan2}*180/{_pi}
    78.         broadcast "<cyan>%vector pitch of vector {_vectorx}, {_vectory}, {_vectorz}% %vector yaw of vector {_vectorx}, {_vectory}, {_vectorz}%"
    79.         broadcast "<gold>%{_RotPitch}% %{_RotYaw}%"
    80.         #Same pitch and yaw : Yaw between [0,360] and [-180,180]
    81.        
    82.        
    83.        
    84.         set {_block} to block at location ({_x}, {_y}, {_z}) in world "%{map}%"
    85.         if {_block} is air or water or any glass pane or carpet or pressure plate or window glass or painting or item frame or sign or button or flower pot or ladder or torch or redstone torch or wire:
    86.             if {_block} is water:
    87.                 if {_predict} is false:
    88.                     if block upward {_block} is air:
    89.                         execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle splash %{_x}% %{_y}+1% %{_z}% 0.1 0 0.1 0 50 force"
    90.                 set {_v0} to {_v0}*0.98
    91.                 if {_v0} < 5:
    92.                     set {_v0} to 5
    93.             if {_block} is glass pane or window glass:
    94.                 if {_predict} is false:
    95.                     set {_blockID} to id of block at location ({_x}, {_y}, {_z}) in world "%{map}%"
    96.                     execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle blockcrack %x-location of {_block}% %y-location of {_block}% %z-location of {_block}% 0.1 0.1 0.1 1 10 force @a %{_blockID} + data of {_block}*4096%"
    97.                     set block at location ({_x}, {_y}, {_z}) in world "%{map}%" to air
    98.                 set {_v0} to {_v0}*0.7
    99.             if {_predict} is false:
    100.                 execute console command "/tp @e[type=ArmorStand,name=%{_ID}%] %{_x}% %{_y}-1% %{_z}% %{_RotYaw}% ~"
    101.                # execute console command "/entitydata @e[type=ArmorStand,name=%{_ID}%] {Pose:{Head:[%({_RotPitch} -90)*-1%f,0f,0f]}}"
    102.                 execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle reddust %{_x}% %{_y}% %{_z}% %{_color}% 1 0 force"
    103.                 execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /playsound minecraft:entity.guardian.ambient master @a %{_x}% %{_y}% %{_z}% 0.1 2"
    104.             add 0.01 to {_t}
    105.            
    106.         else:
    107.             if {_v0} > 5:                                   #no bounce if velocity is under 5 cube/s
    108.                 set {_bx} to x-location of {_block}
    109.                 set {_by} to y-location of {_block}
    110.                 set {_bz} to z-location of {_block}
    111.                
    112.                 #==============
    113.                 #CODE OF BOUNCE
    114.                 #NEED HELP HERE
    115.                 #==============
    116.  
    117.                
    118.                 #set {_pitch} to ???????                                 #NEED to know the new pitch
    119.                 #set {_yaw} to ???????                                   #NEED to know the new yaw
    120.                 #================
    121.                 #NEED HELP UPWARD
    122.                 #================
    123.                
    124.                 #Code below = set the coord of the impact as a new shoot location reference with new pitch and yaw              
    125.                 set {_v0} to {_v0}*0.8
    126.                 set {_x0} to {_x}                                       #{_x}, {_y}, {_z} = Impact location
    127.                 set {_y0} to {_y}
    128.                 set {_z0} to {_z}
    129.                 set {_cosPitch} to cos ({_pitch}*3.14/180)              #Need to know the new {_pitch}
    130.                 set {_cosx} to (sin ({_yaw}*3.14/180) )* {_cosPitch}    #Need to know the new {_yaw}
    131.                 set {_cosz} to (cos ({_yaw}*3.14/180) )* {_cosPitch}
    132.                
    133.                
    134.                
    135.             else:
    136.                 exit loop
    137.         set {_x.old} to {_x}
    138.         set {_y.old} to {_y}
    139.         set {_z.old} to {_z}
    140.         if {_predict} is false:
    141.             if {_t}*100 is divisible by 5:
    142.                 wait 1 tick
    143.     if {_predict} is true:
    144.         set block at location ({_x}, {_y}, {_z}) in world "%{map}%" to glowstone
    145.     execute console command "/kill @e[type=ArmorStand,name=%{_ID}%]"
    146.  
    147. command /predict:                        #the command to do
    148.     trigger:
    149.         Shoot(player,"retardement", 1.4, false)     #set to "true" to predict the trajectory in a 1 tick
    150.         set {map} to event-world                    #DEBUG : I use this on my server
    151.         set {game.timer} to 0                       #DEBUG : I use this on my server
    152.  
    use command "/predict" to see what happen

    Anybody who want help : I have made a test server.rar (28Mo) included all addons +the skript +Viaversion for 1.10.x to 1.11.2
    The first shoot does not works but all other worked :emoji_wink:
    https://drive.google.com/open?id=1AnvC_spWVg2d4TXAPU86cGD5PjsS_Sv-
    Thank you very much for your help !!

     
    #1 aeim, Nov 19, 2017
    Last edited: Nov 20, 2017
  2. Best Answer:
    Post #15 by Syst3ms, Nov 20, 2017
  3. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    So essentially you want to act as if it "bounced" from the center?
     
  4. aeim

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    "bounced" from the impact location (in yellow on my picture)
    The vector Center>>>Impact can be replace as an infinite line

    you can Imagine a normal paper in 2D like in real life,
    you draw 2 dot of fresh ink anywhere,
    you draw a line in a random direction going through one of two points,
    you fold the sheet following this line,
    and a third dot appear (cause it's fresh ink) ... I need to know where is this dot in 3D space

    I can do it if this code :
    Code (Skript):
    1. send "%location at (-1, 0, -1) mirrored at location at (0, 0, 0) in direction of vector 0, 0, -1%"
    but this code result (0, 0, -1) ITS WRONG !! I need (1, 0, -1)

    Anybody who want help : I have made a test server.rar (28Mo) included all addons +the skript +Viaversion for 1.10.x to 1.11.2
    The first shoot does not works but all other worked :emoji_wink:
    https://drive.google.com/open?id=1AnvC_spWVg2d4TXAPU86cGD5PjsS_Sv-

    EDIT : IF it's possible to rebounce as it's a cube and not a sphere is awesome, but realy more difficult :/ (I guess ... no ?) Maybe by the same operation BUT the vector mirror is rouded to 90 degree
     
    #3 aeim, Nov 19, 2017
    Last edited: Nov 19, 2017
  5. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    Can you not just make the x, y and z negative?
     
  6. aeim

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    nowp, does not work.
    This make just a rebound in your face ^^
     
  7. Donut

    Donut Well-Known Member

    Joined:
    Mar 27, 2017
    Messages:
    1,336
    Likes Received:
    177
    Medals:
    Wouldnt it work if you just make the y negative so it goes in the same direction just up instead of down
    [​IMG]
     
  8. aeim

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    this work for upward and downward faces of a block, not horizontal faces :/
     
  9. Donut

    Donut Well-Known Member

    Joined:
    Mar 27, 2017
    Messages:
    1,336
    Likes Received:
    177
    Medals:
    Well for horizontal faces wouldnt it be the same y but negative x and z? Assuming its possible to check which block face the arrow lands on
     
  10. aeim

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    i have an other idea (i know how to code 50%)
    1) Need to know the neerest round 90 degree of vector between the point of impact and the current position = know the one of all 6 Faces of the impact. # I don't know how to do it
    2) Set a mirrored loc at future loc # I can do it
    3) found lenght of h (see the picture below) # I don't know
    4) set lenght of vector to 2*h # I can do it
    5) put the vector to futur loc and apply a translation with vector # I can
    6) Done, you get the Real mirrored dot location

    It's different from my original idea, same result. What is the most easy way? (idk)


    [​IMG]



    @Donut, yes it can work, but how to know the impact faces ?
     
  11. Donut

    Donut Well-Known Member

    Joined:
    Mar 27, 2017
    Messages:
    1,336
    Likes Received:
    177
    Medals:
    The Block#getFace method gives you the face of the block relative to another. So you could get the block where the arrow is (im not sure if the arrow's location is considered in the block it hits or more where the tail is, if it is just subtract a little from its location) then compare it to the block it hits. Also I couldnt find a getFace expression in the skript docs so youll have to use skript-mirror but it looks like youre familar with it
     
  12. aeim

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    Interesting,
    Nowp, i'm not familar with it, I had download it today haha (and i don't know how to read java)

    I have made this :

    TO TEST :
    Code (Skript):
    1. on script load:
    2.   import "java.lang.System"
    3.   import "java.lang.Math"
    4.   import "java.lang.Integer" #This exist ?
    5.  
    6. command /rr <integer=1> <integer=1>:
    7.     trigger:
    8.         set {_x} to arg-1
    9.         set {_y} to 100
    10.         set {_z} to arg-2
    11.         set {_world} to player's world
    12.         set {_Mirror.block} to {_world}.getBlockAt( {_x} and {_y} and {_z} )
    13.         broadcast "%{_Mirror.block}%"
    14.         add 1 to {_y}
    15.         set {_Mirror.target} to world.getBlockAt( {_x} and {_y} and {_z} )
    16.         send "%{_Mirror.block}.getFace({_Mirror.target})%"
    Upward work 100% without any problem

    Code (Skript):
    1.                 set {_bx} to x-location of {_block}
    2.                 set {_by} to y-location of {_block}
    3.                 set {_bz} to z-location of {_block}
    4.  
    5.                 #==============
    6.                 #CODE OF BOUNCE
    7.                 #NEED HELP HERE
    8.                 #==============
    9.                 set {_world} to {_shooter}'s world
    10.                 set {_Mirror.block} to {_world}.getBlockAt( {_bx} and {_by} and {_bz} )
    11.                 broadcast "%{_Mirror.block}%"
    12.                 set {_Mirror.old} to {_world}.getBlockAt( {_x.old} and {_y.old} and {_z.old} )
    13.                 broadcast "%{_Mirror.old}%"
    14.                 set {_Mirror.face} to {_Mirror.block}.getFace({_Mirror.old})
    15.                 broadcast "%{_Mirror.face}%"           #YEAH I have NORTH :)
    16.                 exit loop
    But in a function this work ... and 3 seconds after 1000 lines of [ERROR] appear on my console + the world "{_world}" is DELETED and recreate with a random seed. This appear every time with the function but not with the "/rr"
    If i do :
    !set {test} to player's world
    !send "%{test}.getBlockAt( 0 and 0 and 0 )%"
    This work fine, no crash ... so the Function is the problem ?
     
  13. Sashie

    Addon Developer

    Joined:
    Jan 22, 2017
    Messages:
    52
    Likes Received:
    49
    there's also this way to get a block face(in java)
    Code (Text):
    1.  
    2. targetLocation.getBlock().getFace(location.getBlock());
    3.  
    also from the looks of it, u should be able to get what you want using that mirror/reflect expression from biosphere2 @bio

    Code (Skript):
    1.  
    2. %locations% (mirrored|reflected) at %location%[ (in|with) direction [of ]%-vector%]
    3.  
    you just have to calulate what the direction vector is that you want it mirrored at :emoji_wink:
     
    #12 Sashie, Nov 20, 2017
    Last edited: Nov 20, 2017
  14. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    Instead of calculating weird distances, you can use basic trigonometry. Calculate the angle between the vector rounded to the closest 90° and your input vector. Then you can get a length using "cos(angle) * 2*PreviousImpact". That'll give you 2h.
     
  15. aeim

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    Thx, this reflected expression is perfectly what I

    need but the part "[ (in|with) direction [of ]%-vector%]" is broken, as i said upward in my second reply :

    Or maybe i don't kow how to us this part :/ (If i know how to use it, all of my problem can be solved :emoji_astonished:)


    Ok now i have debug my world reset (the problem was just a # blabla # blabla)
    and i can get the Face of the impact = i can get the vector 90°

    Code (Skript):
    1.                 set {_bx} to x-location of {_block}
    2.                 set {_by} to y-location of {_block}
    3.                 set {_bz} to z-location of {_block}
    4.  
    5.                 #==============
    6.                 #CODE OF BOUNCE
    7.                 #NEED HELP HERE
    8.                 #==============
    9.                 set {_face} to Face({_world}, {_bx}, {_by}, {_bz}, {_x.old}, {_y.old}, {_z.old})
    10.                 broadcast "%{_face}%"
    11.                 if "%{_face}%" is "UP":
    12.                     set {_vector90} to vector 0, 1, 0
    13.                 if "%{_face}%" is "DOWN":
    14.                     set {_vector90} to vector 0, -1, 0
    15.                 if "%{_face}%" is "EAST":
    16.                     set {_vector90} to vector 1, 0, 0
    17.                 if "%{_face}%" is "WEST":
    18.                     set {_vector90} to vector -1, 0, 0
    19.                 if "%{_face}%" is "SOUTH":
    20.                     set {_vector90} to vector 0, 0, 1
    21.                 if "%{_face}%" is "NORTH":
    22.                     set {_vector90} to vector 0, 0, -1
    23.              
    24.                
    (Yeah this is a progress ^^ ... I hope my {_vector90} are in right direction)

    i would like to know the angle between {_vector90} and input vector with basic trigonometry but it's 3D and not 2D and i'm not an expert with that :'(
    (cause of the input vector have a yaw and pitch )

    the code "angle between %vector% and %vector%" does not work and return "can't understand this expression"
     
  16. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    If nothing works, you can use skript-mirror and use the following expression to get the angle :
    Code (Skript):
    1. {_inputVector}.angle({_vector90})
    The thing is, this result is in radians, so the forementioned method would not work. To convert from radians to degrees, use :
    Code (Skript):
    1. (180 * {_radians}) / acos(-1)
    Note : acos(-1) = π
     
  17. aeim

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    Guys ... it ... IT'S WORKING =D !!

    thx everyone !

    Code (Skript):
    1. on script load:
    2.   import "java.lang.System"
    3.   import "java.lang.Math"
    4.   import "java.lang.Integer"
    5.  
    6.  
    7. function Face(world: world, x1: number, y1: number, z1: number, x2: number, y2: number, z2: number) :: string:
    8.     set {_Mirror.block1} to {_world}.getBlockAt( {_x1} and {_y1} and {_z1} )
    9.     set {_Mirror.block2} to {_world}.getBlockAt( {_x2} and {_y2} and {_z2} )
    10.     set {_mirror.face} to {_Mirror.block1}.getFace({_Mirror.block2})
    11.     return "%{_mirror.face}%"
    12.  
    13. function Shoot(shooter: player, type: string, force: number, predict: boolean):
    14.     set {_world} to {_shooter}'s world
    15.     set {_pi} to {Math}.PI!
    16.     set {_x0} to x-location of {_shooter}
    17.     set {_y0} to y-location of {_shooter}
    18.     set {_z0} to z-location of {_shooter}
    19.     set {_v0} to 17.7*{_force}              #17.7 is my own chosen number randomly for the velocity
    20.     set {_pitch} to pitch of {_shooter}*-1  #The rotation of player
    21.     set {_yaw} to yaw of {_shooter}*-1
    22.     set {_cosPitch} to cos ({_pitch}*3.14/180)
    23.     set {_cosx} to (sin ({_yaw}*3.14/180) )* {_cosPitch}
    24.     set {_cosz} to (cos ({_yaw}*3.14/180) )* {_cosPitch}
    25.     set {_t} to 0
    26.     set {_colorRandom} to "1 0 0"
    27.     set {_RotPitch} to {_pitch}             #The initial rotation of projectile
    28.     set {_RotYaw} to {_yaw}
    29.  
    30.     if {_predict} is false:
    31.         set {_ID} to "Shoot_%{_shooter}%_%{game.timer}%"
    32.         run {_shooter} command "/summon ArmorStand %x-location of {_shooter}% %y-location of {_shooter}% %z-location of {_shooter}% {CustomName:""%{_ID}%"",Tags:[""Shoot"",""Shoot_%{_shooter}%""],NoGravity:1b,Small:1b,Marker:1b,Invisible:1,Invulnerable:0,DisabledSlots:2039583}" as op
    33.         loop all armor stands:
    34.             loop-entity's name is "%{_ID}%"
    35.             set {_entity} to loop-entity    #not used for now
    36.             execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /playsound minecraft:entity.irongolem.attack master @a %{_x0}% %{_y0}% %{_z0}% 1 1"
    37.             if "%{player::*}%" contain "%{_shooter}%":
    38.                 execute console command "/mycmd add %{_shooter}% stats.use.%{_type}% 1"
    39.             if "%{_type}%" is "fragmentation":
    40.                 set helmet of loop-entity to yellow dye
    41.                 set {_color} to "0 1 0"
    42.             if "%{_type}%" is "retardement":
    43.                 set helmet of loop-entity to red dye
    44.                 set {_color} to "0 0 0"
    45.             if "%{_type}%" is "chimique":
    46.                 set helmet of loop-entity to light green dye
    47.                 set {_color} to "0.27 0.77 0.18"
    48.             if "%{_type}%" is "flame":
    49.                 set helmet of loop-entity to orange dye
    50.                 set {_color} to "1 0.5 0.1"
    51.             if "%{_type}%" is "implosion":
    52.                 set helmet of loop-entity to light blue dye
    53.                 set {_color} to "0.1 0.9 1"
    54.             if {_color} is not set:
    55.                 set {_color} to "1 1 1"
    56.                
    57.     loop 900 times:
    58.         set {_xt} to {_v0}* {_cosx}         #I put this here cause of the speed {_v0} can be modified (exemple: in water)
    59.         set {_zt} to {_v0}* {_cosz}
    60.         set {_x} to {_x0}+{_xt}*{_t}
    61.         set {_y} to (-12/2*{_t}^2) +{_v0}*{_t}*sin ({_Pitch}*3.14/180) +1.52 +{_y0}     #+1.52 is for eye's position
    62.         set {_z} to {_z0}+{_zt}*{_t}
    63.        
    64.         set {_vectorx} to {_x} - {_x.old}           #I prefer use %vector% only if a complex math operation is more easy with an addon
    65.         set {_vectory} to {_y} - {_y.old}
    66.         set {_vectorz} to {_z} - {_z.old}
    67.         set {_norme} to sqrt ( {_vectorx}^2 + {_vectory}^2 + {_vectorz}^2 )
    68.         set {_vectordirx} to {_vectorx} / {_norme}
    69.         set {_vectordiry} to {_vectory} / {_norme}
    70.         set {_vectordirz} to {_vectorz} / {_norme}
    71.        
    72.  
    73.         set {_RotPitch} to -57.2958* arc sin ({_vectordiry})
    74.         set {_atan2} to {Math}.atan2({_vectordirx} and {_vectordirz})
    75.         set {_RotYaw} to {_atan2}*180/{_pi}
    76.         #broadcast "<cyan>%vector pitch of vector {_vectorx}, {_vectory}, {_vectorz}% %vector yaw of vector {_vectorx}, {_vectory}, {_vectorz}%"
    77.         #broadcast "<gold>%{_RotPitch}% %{_RotYaw}%"
    78.         #Same pitch and yaw : Yaw between [0,360] and [-180,180]
    79.        
    80.        
    81.         set {_block} to block at location ({_x}, {_y}, {_z}) in world "%{map}%"
    82.         if {_block} is air or water or any glass pane or carpet or pressure plate or window glass or painting or item frame or sign or button or flower pot or ladder or torch or redstone torch or wire:
    83.             if {_block} is water:
    84.                 if {_predict} is false:
    85.                     if block upward {_block} is air:
    86.                         execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle splash %{_x}% %{_y}+1% %{_z}% 0.1 0 0.1 0 50 force"
    87.                 set {_v0} to {_v0}*0.98
    88.                 if {_v0} < 5:
    89.                     set {_v0} to 5
    90.             if {_block} is glass pane or window glass:
    91.                 if {_predict} is false:
    92.                     set {_blockID} to id of block at location ({_x}, {_y}, {_z}) in world "%{map}%"
    93.                     execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle blockcrack %x-location of {_block}% %y-location of {_block}% %z-location of {_block}% 0.1 0.1 0.1 1 10 force @a %{_blockID} + data of {_block}*4096%"
    94.                     set block at location ({_x}, {_y}, {_z}) in world "%{map}%" to air
    95.                 set {_v0} to {_v0}*0.7
    96.             if {_predict} is false:
    97.                 execute console command "/tp @e[type=ArmorStand,name=%{_ID}%] %{_x}% %{_y}-1% %{_z}% %{_RotYaw}% ~"
    98.                # execute console command "/entitydata @e[type=ArmorStand,name=%{_ID}%] {Pose:{Head:[%({_RotPitch} -90)*-1%f,0f,0f]}}"
    99.                 execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle reddust %{_x}% %{_y}% %{_z}% %{_color}% 1 0 force"
    100.                 execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /playsound minecraft:entity.guardian.ambient master @a %{_x}% %{_y}% %{_z}% 0.1 2"
    101.             add 0.01 to {_t}
    102.         else:
    103.             if {_v0} > 5:                                   #no bounce if velocity is under 5 cube/s
    104.                 #broadcast "impact: %{_x}% %{_y}% %{_z}%"
    105.                 #broadcast "velocity: %{_v0}% angle: %{_pitch}% %{_yaw}%"
    106.                 set {_bx} to x-location of {_block}
    107.                 set {_by} to y-location of {_block}
    108.                 set {_bz} to z-location of {_block}
    109.                 set {_inputVector} to vector {_x.old}-{_x}, {_y.old}-{_y}, {_z.old}-{_z}
    110.                 #==============
    111.                 #CODE OF BOUNCE
    112.                 #NEED HELP HERE
    113.                 #==============
    114.                 set {_face} to Face({_world}, {_bx}, {_by}, {_bz}, {_x.old}, {_y.old}, {_z.old})
    115.                 if "%{_face}%" is "<none>":
    116.                     if {_RotPitch} > 0:
    117.                         set {_face} to "UP"
    118.                     else:
    119.                         set {_face} to "DOWN"
    120.                 if "%{_face}%" is "UP":
    121.                     set {_vector90} to vector 0, 1, 0
    122.                 if "%{_face}%" is "DOWN":
    123.                     set {_vector90} to vector 0, -1, 0
    124.                 if "%{_face}%" is "EAST":
    125.                     set {_vector90} to vector 1, 0, 0
    126.                 if "%{_face}%" is "WEST":
    127.                     set {_vector90} to vector -1, 0, 0
    128.                 if "%{_face}%" is "SOUTH":
    129.                     set {_vector90} to vector 0, 0, 1
    130.                 if "%{_face}%" is "NORTH":
    131.                     set {_vector90} to vector 0, 0, -1
    132.                 if "%{_face}%" is "SOUTH_WEST":
    133.                     set {_vector90} to vector -1, 0, 1
    134.                 if "%{_face}%" is "SOUTH_EAST":
    135.                     set {_vector90} to vector 1, 0, 1
    136.                 if "%{_face}%" is "NORTH_WEST":
    137.                     set {_vector90} to vector -1, 0, -1
    138.                 if "%{_face}%" is "NORTH_EAST":
    139.                     set {_vector90} to vector 1, 0, -1
    140.                 set {_angle} to {_inputVector}.angle({_vector90}) *180/{_pi}
    141.                 set {_length} to 2* vector length of {_inputVector}
    142.                 set {_length} to {_length} * cos({_angle})
    143.                 set {_vector90} to {_vector90} normalized ** {_length}
    144.                 set {_mirror1} to location ({_x.old}, {_y.old}, {_z.old}) in world "%{_world}%" mirrored at location ({_x}, {_y}, {_z}) in world "%{_world}%"
    145.                 set {_mirror2} to {_mirror1} ~ {_vector90}      #Offset a location by a vector : %location% ~ %vector%
    146.                 set {_VectorRebound} to vector x-location of {_mirror2} - {_x}, y-location of {_mirror2} - {_y}, z-location of {_mirror2} - {_z}
    147.                
    148.                 #loop 90 times:
    149.                 #    execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle reddust %{_x}% %{_y}% %{_z}% 1 0 0 1 0 force"
    150.                 #    execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle reddust %{_x.old}% %{_y.old}% %{_z.old}% 0 1 0 1 0 force"
    151.                 #    execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle reddust %x-location of {_mirror2}% %y-location of {_mirror2}% %z-location of {_mirror2}% 0 0 1 1 0 force"
    152.                 #    wait a tick
    153.                    
    154.                 set {_pitch} to vector pitch of {_VectorRebound}
    155.                 set {_yaw} to vector yaw of {_VectorRebound}
    156.                 set {_pitch} to {_pitch} *-1
    157.                 set {_yaw} to {_yaw} *-1
    158.                 #broadcast "<cyan>%{_pitch}% %{_yaw}%"
    159.                 #================
    160.                 #NEED HELP UPWARD
    161.                 #================
    162.                
    163.                 #Code below = set the coord of the impact as a new shoot location reference with new pitch and yaw              
    164.                 set {_v0} to {_v0}*0.8                               #change to 0.2 for normal rebound
    165.                 set {_x0} to {_x}                                       #{_x}, {_y}, {_z} = Impact location
    166.                 set {_y0} to {_y} -1.52
    167.                 set {_z0} to {_z}
    168.                 set {_cosPitch} to cos ({_pitch}*3.14/180)
    169.                 set {_cosx} to (sin ({_yaw}*3.14/180) )* {_cosPitch}
    170.                 set {_cosz} to (cos ({_yaw}*3.14/180) )* {_cosPitch}
    171.                 set {_t} to 0.05
    172.                 set {_RotPitch} to {_pitch}
    173.                 set {_RotYaw} to {_yaw}
    174.                 set {_colorRandom} to a random element out of "1 1 1", "0 1 0" and "0 0 1"
    175.             else:
    176.                 exit loop
    177.         execute console command "/execute @r ~ ~ ~ /particle reddust %{_x}% %{_y}% %{_z}% %{_colorRandom}% 1 0 force"
    178.         set {_x.old} to {_x}
    179.         set {_y.old} to {_y}
    180.         set {_z.old} to {_z}
    181.         if {_predict} is false:
    182.             if {_t}*100 is divisible by 5:
    183.                 wait 1 tick
    184.     if {_predict} is true:
    185.         set block at location ({_x}, {_y}, {_z}) in world "%{map}%" to glowstone
    186.     execute console command "/kill @e[type=ArmorStand,name=%{_ID}%]"
    187.  
    188. command /predict:
    189.     trigger:
    190.         loop 10 times:
    191.             Shoot(player,"retardement", 1.4, true)      #set to "true" to predict the trajectory in a 1 tick
    192.             wait a second
    193.         #set {map} to event-world                    #DEBUG : I use this on my server
    194.         #set {game.timer} to 0                       #DEBUG : I use this on my server
    You can try this code, (parameter for a lot of rebounce with a lot of color ^^), if you don't have all plugins use this pack:
    and a little bonus bonus, the code for correct mirroring "location at (-1, 0, -1) mirrored at location at (0, 0, 0) in direction of vector 0, 0, -1" of @bi0
    Code (Skript):
    1. on script load:
    2.   import "java.lang.System"
    3.   import "java.lang.Math"
    4.   import "java.lang.Integer"
    5.  
    6.  
    7. command /mirror <integer= 1> <integer= 0> <integer= 0>:
    8.     trigger:
    9.         set {_pi} to {Math}.PI!
    10.         set {_vector90} to vector arg-1, arg-2, arg-3
    11.         set {_inputVector} to vector -1, 0, -1              #=direction of the bullet inverted
    12.         set {_angle} to {_inputVector}.angle({_vector90}) *180/{_pi}
    13.         set {_length} to 2* vector length of {_inputVector}
    14.         set {_length} to {_length} * cos({_angle})
    15.  
    16.         set {_vector90} to {_vector90} normalized ** {_length}
    17.         set {_mirror1} to location (-1, 0, -1) in world "%event-world%" mirrored at location (0, 0, 0) in world "%event-world%"
    18.         set {_vectorMirror1} to vector x-location of {_mirror1}, y-location of {_mirror1}, z-location of {_mirror1}
    19.         set {_mirror2} to {_vectorMirror1} ++ {_vector90}
    20.         broadcast "angle: %{_angle}% cos: %cos({_angle})% length of InputVector: %vector length of {_inputVector}% length: %{_length}%"
    21.         broadcast "<cyan>mirror : %{_mirror2}%"
    I have against some problem with my trajectory but i have learn a lot of thing. I will try to solve them alone.
     

    Attached Files:

    Sashie likes this.
  18. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    Instead of using 3.14 as an approximate for pi, you can make an option like this
    Code (Skript):
    1. options:
    2.     pi : acos(-1)
     
  19. aeim

    aeim Member

    Joined:
    Feb 21, 2017
    Messages:
    38
    Likes Received:
    5
    ok

    Code (Skript):
    1. set {_pi} to {Math}.PI!
    Does not return a good Pi ?
     
  20. Sashie

    Addon Developer

    Joined:
    Jan 22, 2017
    Messages:
    52
    Likes Received:
    49
    or instead of using a function and wasting time to calculate it you should just use `3.1415926535897932` the value itself....
     
  21. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    Oh I didn't see the Math.PI part. But sometimes you use 3.14 instead of it.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...