SHARE
TWEET

Untitled

a guest Jul 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local slimeModel = PartByName("Slime")
  2. local completedSteps = 0
  3. local time = 0
  4. local lastJump = -100
  5.  
  6. function lerp(a, b, c)
  7.     return a + (b - a) * c
  8. end
  9.  
  10. function quadBezier(t, p0, p1, p2)
  11.     local l1 = lerp(p0, p1, t)
  12.     local l2 = lerp(p1, p2, t)
  13.     local quad = lerp(l1, l2, t)
  14.     return quad
  15. end
  16.  
  17. function createSlime(name)
  18.     local slime = slimeModel.Duplicate()
  19.     slime.name = name.."Slime"
  20.     return slime
  21. end
  22.  
  23. function calculateSteps(start,finish)
  24.     local steps = {}
  25.    
  26.     local strideLength = 2 
  27.     local distance = Vector3.Distance(start,finish)
  28.     local direction = (finish-start).normalized
  29.  
  30.     local numSteps = math.ceil(distance/strideLength)
  31.    
  32.     for i = 1,numSteps do
  33.         steps[i] = start + direction*strideLength*i
  34.     end
  35.  
  36.     return steps
  37. end
  38.  
  39. function InitialPlayerSpawn(player)
  40.  
  41. end
  42.  
  43. local slime = createSlime("Quantum")
  44. local start = newVector3(0,0,0)
  45. local finish = newVector3(16,0,0)
  46. local steps = calculateSteps(start,finish)
  47. local currentStep = 1
  48. local currentIteration = 0
  49.  
  50. slime.position = start + newVector3(0,slime.size.y/2 + .05,0)
  51.  
  52. function Update()
  53.     time = time + 1/60
  54.    
  55.     local point = quadBezier(
  56.         currentIteration/60,
  57.         slime.position,
  58.         slime.position + newVector3(0,1,0)
  59.         steps[currentStep]
  60.     )
  61.    
  62.     slime.position = point
  63.  
  64.     currentIteration = currentIteration + 1
  65.     if currentIteration >= 61 then
  66.         currentIteration = 0
  67.         currentStep = currentStep + 1
  68.     end
  69.    
  70.     if (time - lastJump) > 1 then
  71.         lastJump = time
  72.         slime.position = (steps[completedSteps + 1]) + newVector3(0,slime.size.y/2 + .05,0)
  73.         completedSteps = completedSteps + 1
  74.     end
  75.    
  76. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top