Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 11:36 AM |
What should I be attaching what to?
Say I have the gun, and the arm objects
I always end up attaching it to something stupid like the actual head
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 06 Jun 2017 12:23 PM |
Lol attach the arms to the head, the gun to the arms, job done.
|
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 01:19 PM |
arm to cam, arm2 to arm, gun to arm2 its simple the angles u get are local so u just use them on the offsets
|
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 01:40 PM |
@wunder,
can you help me with joint math
im trying to get my Hand (arm has a bicep and a forearm) to reach for a point, but i can't get the weld math right
|
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 01:47 PM |
| ????????? dude like i said before its as simple as using the law of cosines equation 2/|3 1\| where 2 is arm1 1 is arm2 3 is distance this will only account for rotation in 1 direction, do it again to account for up-down rotation etc as needed but u can offset it by direction from arm to handle local function cosine( a,b,c ) --a is left of the angle, b is right of the angle, c is opposite to the angle return math.acos( (a*a + b*b - #### # ####### ) end --arm 1s angle is here /•| \ | local angleOfArm1 = cosine(dist, arm1, arm2) --arm 2s angle is here /| • \| local angleOfArm2 = cosine(arm1, arm2, dist) so u could do something like joint1.C1 = CFrame.Angles(0, angleOfArm1, 0) joint2.C1 = CFrame.Angles(0, angleOfArm2, 0) and like i said to offset u could do something like local anglefrom = CFrame.new( pivotOfArm1, GunGripPos ):toObjectSpace( pivotOfArm1 ) --make it local to pivot joint1.C1 = anglefrom * CFrame.Angles(0, angleOfArm1, 0) |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 01:48 PM |
?????????
dude like i said before its as simple as using the law of cosines equation
2/|3 1\|
where 2 is arm1 1 is arm2 3 is distance
this will only account for rotation in 1 direction, do it again to account for up-down rotation etc as needed but u can offset it by direction from arm to handle
local function cosine( a,b,c ) --a is left of the angle, b is right of the angle, c is opposite to the angle return math.acos( (a * a + b * b - c * #)#/##2#*## * b) ) end
--arm 1s angle is here /•| \ |
local angleOfArm1 = cosine(dist, arm1, arm2)
--arm 2s angle is here /| • \| local angleOfArm2 = cosine(arm1, arm2, dist)
so u could do something like
joint1.C1 = CFrame.Angles(0, angleOfArm1, 0) joint2.C1 = CFrame.Angles(0, angleOfArm2, 0)
and like i said to offset u could do something like
local anglefrom = CFrame.new( pivotOfArm1, GunGripPos ):toObjectSpace( pivotOfArm1 ) --make it local to pivot joint1.C1 = anglefrom * CFrame.Angles(0, angleOfArm1, 0) |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 01:49 PM |
| the equation is _ as ## # ## b, ? as c math.acos( (_ * _ + ! * ! - ? * ?) / (2 * _ * !) ) where a is to the left of the solving angle b is to the right c is the opposite angle (aka the only 1 not forming the angle) |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 01:51 PM |
goo.gl/gUr3PZ
roblox hates trig pastebin version |
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 02:07 PM |
what are the arm1 and arm2 values?
are they just directional vectors?
|
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 02:07 PM |
no look up law of cosine examples |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 02:08 PM |
| most of the time they use a different equation but same variables |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 02:09 PM |
mathsisfun /algebra/images/trig-cosruleex4.gif |
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 02:09 PM |
so its the length of the arms...?
i never took trig, but that looks rite
|
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 02:10 PM |
| yes length of arms and then distance from a to b |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 02:11 PM |
| also it can evaluate to NaN and glitch a bit (only when its too far away or too close) |
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 02:15 PM |
my old method had me projecting the angle onto a plane and getting multiple angles
how do i get other rotational angles using this method?
|
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 02:16 PM |
my other method would allow me to just change the normal of the plane
|
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 02:16 PM |
| ur just solving for angles of the triangle created between the # ###### (pivot of arm1, pivot of arm2, and gun handle) and the way angles work is they are local to the other legs it is connected to so welds should make it fairly easy |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2017 02:18 PM |
if u want to get more angles (not recommended!) u have to do it again for other sides my recommendation is to just shift it over based on the direction of the gun from the pivot (ik will still solve for the distance properly)
and then if u want the arms solving for a different angle (such as bending down and up vs side to side) just rotate the pivot of arm1 a bit |
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 04:18 PM |
Okay. Only issue i have now is what you were talking about earlier with offsets. I can't seem to implement what you have correctly.
Without any changes, the shoulder C0 is: CFrame.new(.4,-1.5,0) * CFrame.Angles(0,math.rad(180),0)
Without any changes, the elbow C0 is: CFrame.new(0,-1.5,0)
ideas?
function rig:rightarmpoint() local position = (self.head.CFrame * CFrame.new(.4,-1.5,0)):toObjectSpace(self.pointTo.CFrame).p print(position.magnitude) self.rightarmchain.target = position self.rightarmchain:solve() local distance = (self.rightarmchain.joints[1] - self.rightarmchain.joints[3]).magnitude local angleOfArm1 = maths.cosine(distance, self.rightarmchain.lengths[1], self.rightarmchain.lengths[2]) local angleOfArm2 = maths.cosine(self.rightarmchain.lengths[1], self.rightarmchain.lengths[2], distance) self.rightshoulder.weld.C1 = CFrame.Angles(angleOfArm1, 0, 0) self.rightelbow.weld.C1 = CFrame.Angles(angleOfArm2, 0, 0) end
|
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 04:27 PM |
that would put the shoulder pivot at about:
self.shoulderpivot = CFrame.new(.4,-.7,0)
local anglefrom = CFrame.new( self.shoulderpivot.p, self.rightarmchain.joints[3] ):toObjectSpace( self.shoulderpivot ) self.rightshoulder.weld.C0 = anglefrom * CFrame.Angles(angleOfArm1, 0, 0)
|
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 05:41 PM |
mk i fixed it, but now i have an error with the rotation i was talking about earlier
prntscr/fgr56v
It can't reach the target because it only rotates on 1 axis.
thoughts?
|
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 06 Jun 2017 06:25 PM |
/57f1f1c08ca6394851de161315242b0f
for some reason it never reaches the goal.
local position = (self.head.CFrame * CFrame.new(.4,-1.5,0)):toObjectSpace(self.pointTo.CFrame).p self.rightarmchain.target = position self.rightarmchain:solve() local distance = (self.rightarmchain.joints[1] - self.rightarmchain.joints[3]).magnitude local angleOfArm1 = maths.cosine(distance, self.rightarmchain.lengths[1], self.rightarmchain.lengths[2]) local angleOfArm2 = maths.cosine(self.rightarmchain.lengths[1], self.rightarmchain.lengths[2], distance) local ToPoint = CFrame.new( (self.head.CFrame * self.shoulderpivot).p, self.pointTo.CFrame.p).lookVector local shoulderRotation = maths.vectortoangle(self.head.CFrame.lookVector, ToPoint, Vector3.new(0,1,0)) self.rightshoulder.weld.C0 = CFrame.new(.4,-.7,0) * CFrame.Angles(0,shoulderRotation,0) * CFrame.Angles(angleOfArm1, 0, 0) self.rightelbow.weld.C1 = CFrame.new(0,-.7,0) * CFrame.Angles(angleOfArm2, 0, 0)
|
|
|
| Report Abuse |
|
|