Discord Thread I need help compacting code

  • 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 community!

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

This thread came from the skUnity Discord. You can't reply to it here but if you join the skUnity Discord, you'll be able to post a reply there. The thread link is part of the thread's message.
Status
Not open for further replies.
code_language.skript:
applescript
  set display scale of {_entity} to vector(1.3,1.4,1.3)
  translate({_entity},vector(0,-1,0), 6 ticks,false)
  wait 6 ticks
  set display scale of {_entity} to vector(1.2,1.5,1.2)
  translate({_entity},vector(0,0.5,0), 6 ticks)
  wait 6 ticks
  set display scale of {_entity} to vector(1.3,1.4,1.3)
  translate({_entity},vector(0,-0.5,0), 5 ticks,false)
  wait 5 ticks
  set display scale of {_entity} to vector(1.2,1.5,1.2)
  translate({_entity},vector(0,0.3,0), 5 ticks)
  wait 5 ticks
  set display scale of {_entity} to vector(1.3,1.4,1.3)
  translate({_entity},vector(0,-0.3,0), 4 ticks,false)
  wait 4 ticks
  set display scale of {_entity} to vector(1.2,1.5,1.2)
  translate({_entity},vector(0,0.15,0), 4 ticks)
  wait 4 ticks
  set display scale of {_entity} to vector(1.25,1.45,1.25)
  translate({_entity},vector(0,-0.15,0), 3 ticks,false)
  wait 3 ticks
  set display scale of {_entity} to vector(1.2,1.5,1.2)
  translate({_entity},vector(0,0.075,0), 3 ticks)
  wait 3 ticks
  set display scale of {_entity} to vector(1.25,1.45,1.25)
  translate({_entity},vector(0,-0.075,0), 2 ticks,false)
  wait 2 ticks
  set display scale of {_entity} to vector(1.2,1.5,1.2)
  translate({_entity},vector(0,0.025,0), 2 ticks)
  wait 2 ticks
  set display scale of {_entity} to vector(1.22,1.48,1.22)
  translate({_entity},vector(0,-0.025,0), 2 ticks, false)
  wait 2 ticks
  set display scale of {_entity} to vector(1.2,1.5,1.2)
  translate({_entity},vector(0,0.01,0), 1 ticks)
  wait 1 ticks
  translate({_entity},vector(0,-0.01,0), 1 ticks,false)
so far the best idea i've had was to add all these values to lists and loop though them

Posted by: publicjake.github.io from the skUnity Discord.
 
Yeah that looks like the way
Since pretty much everything changes (delay, scale, translation vector) and there's no pattern that holds across the entire block

Posted by: mr_darth from the skUnity Discord.
 
there probably is a way with math, because this isn't anything too special but im not a math guys so i had to hardcode it
it makes the entity fall on the ground and bounce up and down like a ball and slowly loses momentum

Posted by: publicjake.github.io from the skUnity Discord.
 
If you want to keep exactly those values, there's nothing you can do really
You can use some physics to do it in the generalised way though

Posted by: mr_darth from the skUnity Discord.
 
code_language.skript:
vb

  set {_h0} to 5
  set {_v} to 0
  set {_g} to 10
  set {_t} to 0
  set {_dt} to 0.001
  set {_rho} to 0.75
  set {_tau} to 0.1
  set {_hmax} to {_h0}
  set {_h} to {_h0}
  set {_hstop} to 0.01
  set {_freeFall} to true
  set {_t_last} to sqrt(2*{_h0}/{_g})*-1
  set {_vmax} to sqrt(2*{_hmax}*{_g})
  while {_hmax} > {_hstop}:
    broadcast 1
    if {_freeFall} is true:
      set {_hnew} to {_h}+{_v}*{_dt}-0.5*{_g}*{_dt}*{_dt}
      if {_hnew} < 0:
        set {_t} to {_t_last}+2*sqrt(2*{_hmax}/{_g})
        set {_freeFall} to false
        set {_t_last} to {_t}+{_tau}
        set {_h} to 0
      else:
        add {_dt} to {_t}
        remove {_g}*{_dt} from {_v}
        set {_h} to {_hnew}
    else:
      add {_tau} to {_t}
      set {_vmax} to {_vmax}*{_rho}
      set {_v} to {_vmax}
      set {_freeFall} to true
      set {_h} to 0
    set {_hmax} to 0.5*{_vmax}*{_vmax}/{_g}
    add {_h} to {_h::*}
    add {_t} to {_t::*}
    wait 1 tick
and now i have an infinite loop, yaaay

Posted by: publicjake.github.io from the skUnity Discord.
 
h is the list of heights
and t is the time at which those heights were registered
Eg. H::1 = 5, T::1 = 7
at t=7s, ball had height of 5m
But those lists are only for the plot

Posted by: mr_darth from the skUnity Discord.
 
Status
Not open for further replies.