SHOW:
|
|
- or go back to the newest paste.
1 | do --CFrame lerp (stravant, clerp by AntiBoomz0r) | |
2 | local function QuaternionFromCFrame(cf) | |
3 | local mx, my, mz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cf:components() | |
4 | local trace = m00 + m11 + m22 | |
5 | if trace > 0 then | |
6 | local s = math.sqrt(1 + trace) | |
7 | local recip = 0.5/s | |
8 | return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5 | |
9 | else | |
10 | local i = 0 | |
11 | if m11 > m00 then | |
12 | i = 1 | |
13 | end | |
14 | if m22 > (i == 0 and m00 or m11) then | |
15 | i = 2 | |
16 | end | |
17 | if i == 0 then | |
18 | local s = math.sqrt(m00-m11-m22+1) | |
19 | local recip = 0.5/s | |
20 | return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip | |
21 | elseif i == 1 then | |
22 | local s = math.sqrt(m11-m22-m00+1) | |
23 | local recip = 0.5/s | |
24 | return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip | |
25 | elseif i == 2 then | |
26 | local s = math.sqrt(m22-m00-m11+1) | |
27 | local recip = 0.5/s return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip | |
28 | end | |
29 | end | |
30 | end | |
31 | local function QuaternionToCFrame(px, py, pz, x, y, z, w) | |
32 | local xs, ys, zs = x + x, y + y, z + z | |
33 | local wx, wy, wz = w*xs, w*ys, w*zs | |
34 | local xx = x*xs | |
35 | local xy = x*ys | |
36 | local xz = x*zs | |
37 | local yy = y*ys | |
38 | local yz = y*zs | |
39 | local zz = z*zs | |
40 | return CFrame.new(px, py, pz,1-(yy+zz), xy - wz, xz + wy,xy + wz, 1-(xx+zz), yz - wx, xz - wy, yz + wx, 1-(xx+yy)) | |
41 | end | |
42 | local function QuaternionSlerp(a, b, t) | |
43 | local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4] | |
44 | local startInterp, finishInterp; | |
45 | if cosTheta >= 0.0001 then | |
46 | if (1 - cosTheta) > 0.0001 then | |
47 | local theta = math.acos(cosTheta) | |
48 | local invSinTheta = 1/math.sin(theta) | |
49 | startInterp = math.sin((1-t)*theta)*invSinTheta | |
50 | finishInterp = math.sin(t*theta)*invSinTheta | |
51 | else | |
52 | startInterp = 1-t | |
53 | finishInterp = t | |
54 | end | |
55 | else | |
56 | if (1+cosTheta) > 0.0001 then | |
57 | local theta = math.acos(-cosTheta) | |
58 | local invSinTheta = 1/math.sin(theta) | |
59 | startInterp = math.sin((t-1)*theta)*invSinTheta | |
60 | finishInterp = math.sin(t*theta)*invSinTheta | |
61 | else | |
62 | startInterp = t-1 | |
63 | finishInterp = t | |
64 | end | |
65 | end | |
66 | return a[1]*startInterp + b[1]*finishInterp, a[2]*startInterp + b[2]*finishInterp, a[3]*startInterp + b[3]*finishInterp, a[4]*startInterp + b[4]*finishInterp | |
67 | end | |
68 | function clerp(a,b,t) | |
69 | local qa = {QuaternionFromCFrame(a)} | |
70 | local qb = {QuaternionFromCFrame(b)} | |
71 | local ax, ay, az = a.x, a.y, a.z | |
72 | local bx, by, bz = b.x, b.y, b.z | |
73 | local _t = 1-t | |
74 | return QuaternionToCFrame(_t*ax + t*bx, _t*ay + t*by, _t*az + t*bz,QuaternionSlerp(qa, qb, t)) | |
75 | end | |
76 | end | |
77 | ||
78 | ||
79 | do --rayCast | |
80 | function rayCast(startpos, Speed, Gravity, Dmg) | |
81 | local ran,err = ypcall(function() | |
82 | local rayPart = Instance.new("Part", char) | |
83 | rayPart.Name = "RayPart" | |
84 | rayPart.BrickColor = BrickColor.new("Really red") | |
85 | rayPart.Anchored = true | |
86 | rayPart.Shape = Shape or "Ball" | |
87 | rayPart.CanCollide = false | |
88 | rayPart.Locked = true | |
89 | rayPart.TopSurface = Enum.SurfaceType.Smooth | |
90 | rayPart.BottomSurface = Enum.SurfaceType.Smooth | |
91 | - | rayPart.Size = Vector3.new(.2, 2, .2) |
91 | + | rayPart.Size = Vector3.new(2, 2, 2) |
92 | local msh = Instance.new("SpecialMesh",rayPart) | |
93 | - | msh.MeshId = "http://www.roblox.com/asset/?id=16190555" |
93 | + | msh.MeshId = "http://www.roblox.com/asset/?id=94316226" |
94 | - | msh.TextureId = "http://www.roblox.com/asset/?id=16190577" |
94 | + | msh.TextureId = "http://www.roblox.com/asset/?id=94257533" |
95 | msh.Scale = Vector3.new(2, 2, 2) | |
96 | ||
97 | ||
98 | ||
99 | ||
100 | local bulletposition = startpos.Position | |
101 | rayPart.CFrame = startpos.CFrame | |
102 | ||
103 | local bulletvelocity = (Vector3.new(math.random(-2,2), math.random(-2,2), math.random(-2,2)))+( mouse.Hit.p - bulletposition).unit*Speed | |
104 | local bulletlastposition = bulletposition | |
105 | ||
106 | ||
107 | ||
108 | coroutine.resume(coroutine.create(function() | |
109 | while true do | |
110 | local dt = wait() | |
111 | bulletlastposition = bulletposition | |
112 | bulletvelocity = bulletvelocity + (Vector3.new(0, -3.81*Gravity, 0)*dt) | |
113 | bulletposition = bulletposition + (bulletvelocity*dt) | |
114 | ||
115 | local ray = Ray.new(bulletlastposition, (bulletposition - bulletlastposition)) | |
116 | ||
117 | local hit, hitposition = workspace:FindPartOnRayWithIgnoreList( ray, { char, rayPart, camera} ) | |
118 | ||
119 | if (torso.Position - rayPart.Position).magnitude > 540 then | |
120 | rayPart:Destroy() | |
121 | break | |
122 | end | |
123 | ||
124 | ||
125 | if hit then | |
126 | local damage = math.random(Dmg, Dmg+6) | |
127 | if hit.Parent:findFirstChild("Humanoid") ~= nil then | |
128 | hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage | |
129 | elseif hit.Parent:IsA("Hat") and hit.Parent.Parent:findFirstChild("Humanoid") then | |
130 | hit.Parent.Parent.Humanoid.Health = hit.Parent.Parent.Humanoid.Health - damage | |
131 | end | |
132 | bulletposition = hitposition | |
133 | rayPart.CFrame = CFrame.new(bulletposition, bulletposition+bulletvelocity) * CFrame.Angles(math.pi/2, 0, 0) | |
134 | for i = 1, 50 do | |
135 | local s = Instance.new("Part") | |
136 | s.CanCollide = false | |
137 | s.Shape = 1 | |
138 | s.Locked = true | |
139 | s.formFactor = "Custom" | |
140 | pl = Instance.new("PointLight", s) | |
141 | pl.Range = 8 | |
142 | pl.Color = Color3.new(0.8, 0.8, 0) | |
143 | - | s.Size = Vector3.new(.3,.3,.3) |
143 | + | s.Size = Vector3.new(0.2,0.2,0.2) |
144 | s.Transparency = 0.5 | |
145 | s.BrickColor = BrickColor.new("Brick yellow") | |
146 | s.MeshId = "http://www.roblox.com/asset/?id=168892432" | |
147 | - | s.Velocity = 0.5 * v |
147 | + | s.TextureId = "http://www.roblox.com/asset/?id=168892465" |
148 | local v = Vector3.new(math.random(-1,1), math.random(1,2), math.random(-1,1)) | |
149 | s.Velocity = 0.2 * v | |
150 | s.CFrame = CFrame.new(rayPart.Position + v, v) | |
151 | s.Parent = workspace | |
152 | coroutine.resume(coroutine.create(function() | |
153 | wait(2) | |
154 | s:Destroy() | |
155 | end)) | |
156 | end | |
157 | rayPart:Destroy() | |
158 | break | |
159 | end | |
160 | rayPart.CFrame = CFrame.new(bulletposition, bulletposition+bulletvelocity) * CFrame.Angles(math.pi/2, 0, 0) | |
161 | rayPart.Parent = workspace | |
162 | end | |
163 | end)) | |
164 | end) | |
165 | if not ran and err then | |
166 | print(err) | |
167 | end | |
168 | end | |
169 | end | |
170 | ||
171 | do --the animating | |
172 | plr = game:service'Players'.LocalPlayer | |
173 | char = plr.Character | |
174 | mouse = plr:GetMouse() | |
175 | humanoid = char:findFirstChild("Humanoid") | |
176 | torso = char:findFirstChild("Torso") | |
177 | head = char.Head | |
178 | ra = char:findFirstChild("Right Arm") | |
179 | la = char:findFirstChild("Left Arm") | |
180 | rl = char:findFirstChild("Right Leg") | |
181 | ll = char:findFirstChild("Left Leg") | |
182 | rs = torso:findFirstChild("Right Shoulder") | |
183 | ls = torso:findFirstChild("Left Shoulder") | |
184 | rh = torso:findFirstChild("Right Hip") | |
185 | lh = torso:findFirstChild("Left Hip") | |
186 | neck = torso:findFirstChild("Neck") | |
187 | rj = char:findFirstChild("HumanoidRootPart"):findFirstChild("RootJoint") | |
188 | anim = char:findFirstChild("Animate") | |
189 | rootpart = char:findFirstChild("HumanoidRootPart") | |
190 | camera = workspace.CurrentCamera | |
191 | ||
192 | ||
193 | local rm = Instance.new("Weld", torso) | |
194 | rm.C0 = CFrame.new(1.5, 0.5, 0) | |
195 | rm.C1 = CFrame.new(0, 0.5, 0) | |
196 | rm.Part0 = torso | |
197 | rm.Part1 = ra | |
198 | local lm = Instance.new("Weld", torso) | |
199 | lm.C0 = CFrame.new(-1.5, 0.5, 0) | |
200 | lm.C1 = CFrame.new(0, 0.5, 0) | |
201 | lm.Part0 = torso | |
202 | lm.Part1 = la | |
203 | ||
204 | ||
205 | ||
206 | local speed = 0.3 | |
207 | local angle = 0 | |
208 | local anglespeed = 1 | |
209 | rsc0 = rm.C0 | |
210 | lsc0 = lm.C0 | |
211 | rjc0 = rj.C0 | |
212 | neckc0 = neck.C0 | |
213 | radian = math.rad | |
214 | ||
215 | apple = Instance.new("Part", char) | |
216 | apple.FormFactor = "Custom" | |
217 | apple.Size = Vector3.new(1, 1, 1) | |
218 | apple:breakJoints() | |
219 | local wld = Instance.new("Weld", char) | |
220 | wld.C1 = CFrame.new(0, -1, 0) | |
221 | wld.C0 = CFrame.Angles(math.pi, 0, 0) | |
222 | wld.Part1 = ra | |
223 | wld.Part0 = apple | |
224 | local msh = Instance.new("SpecialMesh", apple) | |
225 | msh.MeshId = "http://www.roblox.com/asset/?id=16190555" | |
226 | msh.TextureId = "http://www.roblox.com/asset/?id=16190577" | |
227 | msh.Scale = Vector3.new(2, 2, 2) | |
228 | ||
229 | ||
230 | ||
231 | mouse.Button1Down:connect(function() | |
232 | if throwing then return end | |
233 | throwing = true | |
234 | wait(wait()*8) | |
235 | for trans = 1, 0, -0.1 do | |
236 | apple.Transparency = trans | |
237 | wait() | |
238 | end | |
239 | end) | |
240 | ||
241 | done = false | |
242 | while wait() do | |
243 | angle = (angle % 100) + anglespeed/10 | |
244 | mvmnt = math.pi * math.sin(math.pi*2/100*(angle*10)) | |
245 | local rscf = rsc0 | |
246 | local lscf = lsc0 | |
247 | local rjcf = rjc0 | |
248 | local ncf = neckc0 | |
249 | lscf = lsc0 * CFrame.Angles(-radian(5), 0, -radian(5)) | |
250 | if throwing then | |
251 | for waiting = 0, 250, 30 do | |
252 | if done then return end | |
253 | rscf = rsc0 * CFrame.Angles(radian(waiting), 0, 0) | |
254 | rm.C0 = clerp(rm.C0,rscf,speed) | |
255 | wait() | |
256 | if waiting == 250 then | |
257 | done = true | |
258 | end | |
259 | end | |
260 | rscf = rsc0 * CFrame.Angles(radian(120), 0, 0) | |
261 | rayCast(apple, math.random(140, 150), 20, 28) | |
262 | throwing = false | |
263 | done = false | |
264 | end | |
265 | rm.C0 = clerp(rm.C0,rscf,speed) | |
266 | lm.C0 = clerp(lm.C0,lscf,speed) | |
267 | rj.C0 = clerp(rj.C0,rjcf,speed) | |
268 | neck.C0 = clerp(neck.C0,ncf,speed) | |
269 | end | |
270 | end |