|
| 23 Jan 2017 01:17 PM |
I was trying to understand a script from a butterfly model. How does one learn the math behind this stuff below involved with game programming? Basic school trig classes didn't teach this. I love to script but struggle with math. Any idea's where to learn?
while alive do game:GetService("RunService").RenderStepped:wait(); local flat, up = Vector3.new(0, 0.1, 0.3), Vector3.new(0, 0.9, 0); head.CFrame = CFrame.new( from * flat + from * up, (2*from - position)*flat + from * up) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.Angles(math.pi * -0.1, 0, 0); from = position; position = position + Vector3.new( math.cos(direction) * speed, (chord(0.4) - 0.5 + chord(5) + chord(7) - 1) * speed, math.sin(direction) * speed ); --local facing = ((position - from) * Vector3.new(1, 0, 1)).unit; --local factor = facing:Dot( (home - position).unit ); local distance = (home - position).magnitude; local power = 1 - math.exp(-distance ^ 2 / 50); --factor = -factor * power * 5 + 1; local rd = Vector3.new(-math.sin(direction), 0, math.cos(direction)); local turn = rd:Dot( (home - position).unit ) * power; direction = direction + ((chord(2) + chord(4.123) - 1) / 4 + turn / 10) / 2; -- local h = head.CFrame * CFrame.Angles(math.pi / 2, 0, 0); local angle = 0.1 + chord(.717/2) * 1 + 0.9 * chord(2.13/2); local r = 0.2; local dx = math.cos(angle) * r; local dy = math.sin(angle) * r; -- right.CFrame = head.CFrame * CFrame.Angles(-math.pi / 2, 0, 0) * CFrame.new(0, 0, -0.2) * CFrame.new(-0.04, 0.04, 0) * CFrame.new(-dx, dy, 0) * CFrame.Angles(0, 0, -angle) * CFrame.Angles(3, 0.07, 0) -- left.CFrame = head.CFrame * CFrame.Angles(-math.pi / 2, 0, 0) * CFrame.new(0, 0, -0.2) * CFrame.new(0.03, 0.04, 0) * CFrame.new(dx, dy, 0) * CFrame.Angles(0, 0, angle) * CFrame.Angles(0, 0.07, 0) -- animate(); end end |
|
|
| Report Abuse |
|
|
| 23 Jan 2017 01:18 PM |
| Soz don't know how to help |
|
|
| Report Abuse |
|
| |
| |
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 23 Jan 2017 01:58 PM |
What exactly do you need to know? You just study cframing about you find an algorithm that achieves what you want. Then its just tweaking the values.
|
|
|
| Report Abuse |
|