| |
|
»
»
|
|
| |
Can anyone explain this math stuff to me?
|
|
|
NeverEvan
|
  |
| Joined: 15 Oct 2010 |
| Total Posts: 109 |
|
|
| 19 Apr 2015 04:00 PM |
local tCFrame = torso.CFrame local dir = (tCFrame*Vector3.new(-1.5, .5, 0) - mouse.Hit.p).unit local x = Vector3.new(0,1):Cross(dir) local z = x:Cross(dir) weld1.C0 = tCFrame:inverse()*(CFrame.new(0,0,0, x.x, dir.x, z.x, x.y, dir.y, z.y, x.z, dir.z, z.z) + tCFrame*Vector3.new(-1.5, .5, 0) - dir/2)*weld1.C1 local dir = (tCFrame*Vector3.new( 1.5, .5, 0) - mouse.Hit.p).unit local x = Vector3.new(0,1):Cross(dir) local z = x:Cross(dir) weld2.C0 = tCFrame:inverse()*(CFrame.new(0,0,0, x.x, dir.x, z.x, x.y, dir.y, z.y, x.z, dir.z, z.z) + tCFrame*Vector3.new( 1.5, .5, 0) - dir/2)*weld2.C1
Trying to make the arms rotate towards the camera, like in FPS guns, searched it in freemodels, saw this math stuff in a script, don't understand it. |
|
|
| Report Abuse |
|
|
NeverEvan
|
  |
| Joined: 15 Oct 2010 |
| Total Posts: 109 |
|
| |
|
NeverEvan
|
  |
| Joined: 15 Oct 2010 |
| Total Posts: 109 |
|
| |
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 19 Apr 2015 04:10 PM |
| Good luck. I do complex trigonometry stuff with CFrame and I still have no idea what any of that is supposed to do. |
|
|
| Report Abuse |
|
|
droy
|
  |
| Joined: 19 May 2008 |
| Total Posts: 286 |
|
|
| 19 Apr 2015 04:11 PM |
o.o
Droy || Graphic Desiger || Founder of Metados |
|
|
| Report Abuse |
|
|
NeverEvan
|
  |
| Joined: 15 Oct 2010 |
| Total Posts: 109 |
|
|
| 19 Apr 2015 04:15 PM |
| ok well since it seems like no one knows what this is, anyone know how to make the arms rotate towards the camera, like in fps guns? |
|
|
| Report Abuse |
|
|
|
| 19 Apr 2015 04:41 PM |
like this?
local tCFrame = torso.CFrame local dir = (tCFrame*Vector3.new(-1.5, .5, 0) - mouse.Hit.p).unit local x = Vector3.new(0,1):Cross(dir) local z = x:Cross(dir) weld1.C0 = tCFrame:inverse()*(CFrame.new(0,0,0, x.x, dir.x, z.x, x.y, dir.y, z.y, x.z, dir.z, z.z) + tCFrame*Vector3.new(-1.5, .5, 0) - dir/2)*weld1.C1 local dir = (tCFrame*Vector3.new( 1.5, .5, 0) - mouse.Hit.p).unit local x = Vector3.new(0,1):Cross(dir) local z = x:Cross(dir) weld2.C0 = tCFrame:inverse()*(CFrame.new(0,0,0, x.x, dir.x, z.x, x.y, dir.y, z.y, x.z, dir.z, z.z) + tCFrame*Vector3.new( 1.5, .5, 0) - dir/2)*weld2.C1
:3 |
|
|
| Report Abuse |
|
|
|
| 19 Apr 2015 04:41 PM |
| I will look into it tomorrow. It's getting pretty late here. |
|
|
| Report Abuse |
|
|
|
| 20 Apr 2015 03:00 PM |
Okay, it took me some time. But here you have your explanation. I will be brief so if you have further question regarding my explanation feel free to ask.
first of:
local tCFrame = torso.CFrame local dir = (tCFrame*Vector3.new(-1.5, .5, 0) - mouse.Hit.p).unit
This part is pretty simple, it just calculates the direction you're aiming at. I'd write it like this for readability:
local tCFrame = torso.CFrame local start = torso.CFrame*Vector3.new(-1.5, .5, 0) local dir = (start - mouse.Hit.p).unit
Now the hard part:
local x = Vector3.new(0,1):Cross(dir) local z = x:Cross(dir) weld1.C0 = tCFrame:inverse()*(CFrame.new(0,0,0, x.x, dir.x, z.x, x.y, dir.y, z.y, x.z, dir.z, z.z) + tCFrame*Vector3.new(-1.5, .5, 0) - dir/2)*weld1.C1
first off I take out this part
local x = Vector3.new(0,1):Cross(dir) local z = x:Cross(dir) local dirCFrame = CFrame.new(0,0,0, x.x, dir.x, z.x, x.y, dir.y, z.y, x.z, dir.z, z.z)
(dirCFrame value added for explanation) It may surprises you, but this is just an optimized way to do this:
local dirCFrame = CFrame.new(Vector3.new(0,0,0), dir)*CFrame.Angles(-math.pi/2,0,0)
As for the whole weld1.C1 mess. it simplifies to this:
weld1.C0 = tCFrame:inverse()*(dirCFrame + start - dir/2)*weld1.C1
The second half is just the same with another "start" position.
I hope that helped |
|
|
| Report Abuse |
|
|
|
| |
|
|
| |
|
»
»
|
|
|
|
|