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
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).
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
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
https://drive.google.com/open?id=1AnvC_spWVg2d4TXAPU86cGD5PjsS_Sv-
Thank you very much for your help !!
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
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).
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_language.skript:
on script load:
import "java.lang.System"
import "java.lang.Math"
command /rr <number> <number>: #this is just a test
trigger:
set {_x} to arg-1
set {_z} to arg-2
set {_pi} to {Math}.PI!
set {_atan2} to {Math}.atan2({_x} and {_z})
set {_yaw} to {_atan2}*180/{_pi}
broadcast "%{_yaw}% %vector yaw of vector {_x}, 0, {_z}%" #2 method to get yaw, first between [-180,180] , second between [0,360]
function Shoot(shooter: player, type: string, force: number, predict: boolean):
set {_pi} to {Math}.PI!
set {_x0} to x-location of {_shooter}
set {_y0} to y-location of {_shooter}
set {_z0} to z-location of {_shooter}
set {_pitch} to pitch of {_shooter}*-1 #The rotation of player
set {_yaw} to yaw of {_shooter}*-1
set {_v0} to 17.7*{_force} #17.7 is my own chosen number randomly for the velocity
set {_cosPitch} to cos ({_pitch}*3.14/180)
set {_cosx} to (sin ({_yaw}*3.14/180) )* {_cosPitch}
set {_cosz} to (cos ({_yaw}*3.14/180) )* {_cosPitch}
set {_t} to 0
set {_RotPitch} to {_pitch} #The rotation of projectile
set {_RotYaw} to {_yaw}
if {_predict} is false:
set {_ID} to "Shoot_%{_shooter}%_%{game.timer}%"
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
loop all armor stands:
loop-entity's name is "%{_ID}%"
set {_entity} to loop-entity #not used for now
execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /playsound minecraft:entity.irongolem.attack master @a %{_x0}% %{_y0}% %{_z0}% 1 1"
if "%{player::*}%" contain "%{_shooter}%":
execute console command "/mycmd add %{_shooter}% stats.use.%{_type}% 1"
if "%{_type}%" is "fragmentation":
set helmet of loop-entity to yellow dye
set {_color} to "0 1 0"
if "%{_type}%" is "retardement":
set helmet of loop-entity to red dye
set {_color} to "0 0 0"
if "%{_type}%" is "chimique":
set helmet of loop-entity to light green dye
set {_color} to "0.27 0.77 0.18"
if "%{_type}%" is "flame":
set helmet of loop-entity to orange dye
set {_color} to "1 0.5 0.1"
if "%{_type}%" is "implosion":
set helmet of loop-entity to light blue dye
set {_color} to "0.1 0.9 1"
if {_color} is not set:
set {_color} to "1 1 1"
loop 900 times:
set {_xt} to {_v0}* {_cosx} #I put this here cause of the speed {_v0} can be modified (exemple: in water)
set {_zt} to {_v0}* {_cosz}
set {_x} to {_x0}+{_xt}*{_t}
set {_y} to (-12/2*{_t}^2) +{_v0}*{_t}*sin ({_Pitch}*3.14/180) +1.52 +{_y0} #+1.52 is for eye's position
set {_z} to {_z0}+{_zt}*{_t}
set {_vectorx} to {_x} - {_x.old} #I prefer use %vector% only if a complex math operation is more easy with an addon
set {_vectory} to {_y} - {_y.old}
set {_vectorz} to {_z} - {_z.old}
set {_norme} to sqrt ( {_vectorx}^2 + {_vectory}^2 + {_vectorz}^2 )
set {_vectordirx} to {_vectorx} / {_norme}
set {_vectordiry} to {_vectory} / {_norme}
set {_vectordirz} to {_vectorz} / {_norme}
set {_RotPitch} to -57.2958* arc sin ({_vectordiry})
set {_atan2} to {Math}.atan2({_vectordirx} and {_vectordirz})
set {_RotYaw} to {_atan2}*180/{_pi}
broadcast "<cyan>%vector pitch of vector {_vectorx}, {_vectory}, {_vectorz}% %vector yaw of vector {_vectorx}, {_vectory}, {_vectorz}%"
broadcast "<gold>%{_RotPitch}% %{_RotYaw}%"
#Same pitch and yaw : Yaw between [0,360] and [-180,180]
set {_block} to block at location ({_x}, {_y}, {_z}) in world "%{map}%"
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:
if {_block} is water:
if {_predict} is false:
if block upward {_block} is air:
execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle splash %{_x}% %{_y}+1% %{_z}% 0.1 0 0.1 0 50 force"
set {_v0} to {_v0}*0.98
if {_v0} < 5:
set {_v0} to 5
if {_block} is glass pane or window glass:
if {_predict} is false:
set {_blockID} to id of block at location ({_x}, {_y}, {_z}) in world "%{map}%"
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%"
set block at location ({_x}, {_y}, {_z}) in world "%{map}%" to air
set {_v0} to {_v0}*0.7
if {_predict} is false:
execute console command "/tp @e[type=ArmorStand,name=%{_ID}%] %{_x}% %{_y}-1% %{_z}% %{_RotYaw}% ~"
# execute console command "/entitydata @e[type=ArmorStand,name=%{_ID}%] {Pose:{Head:[%({_RotPitch} -90)*-1%f,0f,0f]}}"
execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /particle reddust %{_x}% %{_y}% %{_z}% %{_color}% 1 0 force"
execute console command "/execute @e[type=ArmorStand,name=%{_ID}%] ~ ~ ~ /playsound minecraft:entity.guardian.ambient master @a %{_x}% %{_y}% %{_z}% 0.1 2"
add 0.01 to {_t}
else:
if {_v0} > 5: #no bounce if velocity is under 5 cube/s
set {_bx} to x-location of {_block}
set {_by} to y-location of {_block}
set {_bz} to z-location of {_block}
#==============
#CODE OF BOUNCE
#NEED HELP HERE
#==============
#set {_pitch} to ??????? #NEED to know the new pitch
#set {_yaw} to ??????? #NEED to know the new yaw
#================
#NEED HELP UPWARD
#================
#Code below = set the coord of the impact as a new shoot location reference with new pitch and yaw
set {_v0} to {_v0}*0.8
set {_x0} to {_x} #{_x}, {_y}, {_z} = Impact location
set {_y0} to {_y}
set {_z0} to {_z}
set {_cosPitch} to cos ({_pitch}*3.14/180) #Need to know the new {_pitch}
set {_cosx} to (sin ({_yaw}*3.14/180) )* {_cosPitch} #Need to know the new {_yaw}
set {_cosz} to (cos ({_yaw}*3.14/180) )* {_cosPitch}
else:
exit loop
set {_x.old} to {_x}
set {_y.old} to {_y}
set {_z.old} to {_z}
if {_predict} is false:
if {_t}*100 is divisible by 5:
wait 1 tick
if {_predict} is true:
set block at location ({_x}, {_y}, {_z}) in world "%{map}%" to glowstone
execute console command "/kill @e[type=ArmorStand,name=%{_ID}%]"
command /predict: #the command to do
trigger:
Shoot(player,"retardement", 1.4, false) #set to "true" to predict the trajectory in a 1 tick
set {map} to event-world #DEBUG : I use this on my server
set {game.timer} to 0 #DEBUG : I use this on my server
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
https://drive.google.com/open?id=1AnvC_spWVg2d4TXAPU86cGD5PjsS_Sv-
Thank you very much for your help !!
Last edited: