generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Can anyone explain this math stuff to me?

Previous Thread :: Next Thread 
NeverEvan is not online. 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 is not online. NeverEvan
Joined: 15 Oct 2010
Total Posts: 109
19 Apr 2015 04:02 PM
b1
Report Abuse
NeverEvan is not online. NeverEvan
Joined: 15 Oct 2010
Total Posts: 109
19 Apr 2015 04:08 PM
going to keep bumping
b2
Report Abuse
NotAshley is not online. 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 is not online. 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 is not online. 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
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
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
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
19 Apr 2015 04:41 PM
I will look into it tomorrow. It's getting pretty late here.
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image