|
| 12 Feb 2014 11:49 PM |
I have two CFrames, say x = CFrame.Angles(math.rad(5),0,0) y = CFrame.Angles(math.rad(2),0,0)
I want the difference between y and x, as in x-y = CFrame.Angles(math.rad(-3),0,0) --I know it's not how one would do it, but that's what I need.
Any ideas on how I do this? Keep in mind, x-y ~= y-x, so the dot product method won't work. |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 12:09 AM |
p.s.
I suppose I am sort of asking for the angle between two vectors, but not exactly, as I want to know whether the angle is negative or not. |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Feb 2014 12:29 AM |
d = Math.abs(a - b) % 360
if d > 180 then d = 360 - d end
Want to learn Java? Contact me or visit http://www.roblox.com/Groups/group.aspx?gid=632774 |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 12:29 AM |
Convert to degrees for that to work
Want to learn Java? Contact me or visit http://www.roblox.com/Groups/group.aspx?gid=632774 |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 12:30 AM |
| Erm - where do the CFrames go? |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 12:34 AM |
Let me rephrase my question:
I have the lookVector of two different parts, and I would like to find the angle between them. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 13 Feb 2014 12:37 AM |
math.acos(lv1:Dot(lv2)) try that |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 12:38 AM |
"p.s.
I suppose I am sort of asking for the angle between two vectors, but not exactly, as I want to know whether the angle is negative or not."
acos only returns the absolute value of the angle. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 13 Feb 2014 12:42 AM |
| what do you mean, negative? 270 would just be the same as -90 |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 12:50 AM |
| Acos returns up to pi only. :/ |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 12:54 AM |
@cntkillme I don't have much experience with the Dot product, however I'm pretty sure the range is only between 0 and 180. After all, it is the shortest angle between two lines.
@theroadrunner Consider anything past 90 as a negative angle, since if the angle is more than 90 degrees then they'll be pointing in opposite directions. Otherwise, use toEulerAnglesXYZ?
If that doesn't help, then what are you trying to do? |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 12:55 AM |
Say I have:
^ x | | O--> y
X and Y are two lookVectors. What I want is how much x would need to rotate to be y, e.g.
how much x would need to rotate to be y: -90 degrees how much y would need to rotate to be x: 90 degrees |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 13 Feb 2014 12:59 AM |
Mk, I will give a quick "snapshot" of part of my script:
b is a part c is a weld
while wait(5) do
local goalpos = script.mouseHit.Value local oldCF = b.CFrame oldCF = oldCF - oldCF.p local dirCF = CFrame.new(b.Position, Vector3.new(goalpos.x, b.Position.y, goalpos.z)) dirCF = dirCF - dirCF.p c.C0 = c.C0 * dirCF b.CFrame = b.CFrame * dirCF
end |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 01:01 AM |
| What the script is trying to do is, rotate a model to point at a position (mouseHit), and rotate the lower half of the model back using the weld. The weld works, but the part doesn't. |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 01:03 AM |
Would atan2 work? Not sure if it returns the angle between the two.
'math.atan2 (y, x)'
y & x are vector3s, right? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 13 Feb 2014 01:05 AM |
Oh, you could just point a part to a position easily: part.CFrame = CFrame.new(part.Position, Vector3.new(x, y, z)) |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 01:11 AM |
Tried doing
while wait(5) do local goalpos = script.mouseHit.Value local oldCF = b.CFrame oldCF = oldCF - oldCF.p local dirCF = CFrame.new(b.Position, Vector3.new(goalpos.x, b.Position.y, goalpos.z)) dirCF = dirCF - dirCF.p b.CFrame = CFrame.new(b.Position, Vector3.new(goalpos.x, b.Position.y, goalpos.z)) wait(5) c.C0 = c.C0 * dirCF end
Now the model turns to look at it, but the weld doesn't turn back correctly. |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 01:18 AM |
When I do
while wait(5) do local goalpos = script.mouseHit.Value local oldCF = b.CFrame oldCF = oldCF - oldCF.p local dirCF = CFrame.new(b.Position, Vector3.new(goalpos.x, b.Position.y, goalpos.z)) dirCF = dirCF - dirCF.p c.C0 = c.C0 * dirCF b.CFrame = b.CFrame*dirCF end
The model turns to face A point, and the legs turn back correctly. However, the point isn't script.mouseHit.Value. |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 01:22 AM |
AAAAnyways....
I need a way to find the difference between dirCF and oldCF. |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 01:35 AM |
| Eh, this post has become too complicated, so I'll rephrase my question and make a new post. |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 01:36 AM |
local acos = math.acos local sin = math.sin local cos = math.cos
function Slerp(lv1,lv2,t) local a = math.acos(lv1:Dot(lv2)) if a == 0 then --They are perpendicular a = t*pi/2 return lv1*cos(a) + lv2*cos(a) else return (sin((1-t)*a)/sin(a))*lv1 + (sin(t*a)/sin(a))*lv2 end end
--[[
There we go, it took me a while but I got it. I think the first two arguments are easy to guess, while the third argument represents time on a value from 0 to 1. This will return the lookVector between lv1 and lv2 during the time of t.
Not sure if this is exactly what you were wanting, but perhaps it'll help?
]]
|
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 01:41 AM |
Holy mother of pearl.
That - that is beautiful.
What does t do? |
|
|
| Report Abuse |
|
|