|
| 10 Feb 2016 04:21 PM |
CFrame.new(game.Workspace.Part2.CFrame.p * Vector3.new(-1,1,1),game.Workspace.Part1.Position + game.Workspace.Part2.CFrame.lookVector * Vector3.new(-1,1,1))
Positioning is perfect, my issue is the rotation. What that top code does is reverse a part in order to successfully create a "mirror". My problem is the rotation isn't reversed correctly. How can I fix this? |
|
|
| Report Abuse |
|
| |
EgoMoose
|
  |
| Joined: 04 Feb 2009 |
| Total Posts: 2896 |
|
|
| 10 Feb 2016 05:36 PM |
Ahh, this is an interesting one. The way I'd approach is it via altering the CFrame matrix.
Give me a few mins to type up an answer, hopefully I won't get ninja'd! |
|
|
| Report Abuse |
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 10 Feb 2016 05:39 PM |
Try this? CFrame.new(game.Workspace.Part2.CFrame.p * Vector3.new(-1,1,1),game.Workspace.Part1.Position + -game.Workspace.Part2.CFrame.lookVector * Vector3.new(-1,1,1))
|
|
|
| Report Abuse |
|
|
| 10 Feb 2016 05:57 PM |
@Tynezz Nope! Made it worse tbh! |
|
|
| Report Abuse |
|
EgoMoose
|
  |
| Joined: 04 Feb 2009 |
| Total Posts: 2896 |
|
|
| 10 Feb 2016 06:19 PM |
A CFrame's matrix is made up of 12 components like this:
CFrame.new(x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22);
For now, let's just ignore x, y, and z. They're simply positional values and that's pretty straight forward. What we care about is r00, r01, r02, r10, r11, r12, r20, r21, r22. These our our CFrame's rotation components and they actually represent 3 seperate directional vectors. They're easier to see if we order them like this
r00, r01, r02, r10, r11, r12, r20, r21, r22
Each vertical column is a seperate unit vector.
The first column represents the facing direction of the right surface The second column represents the facing direction of the top surface The third column represents the facing direction of the back surface
As such we can conclude that:
local rightSurface = Vector3.new(r00, r10, r20); local topSurface = Vector3.new(r01, r11, r21); local backSurface = Vector3.new(r02, r12, r22);
Since we know that it's just a matter of fliping our matrix around 180 degrees. So by thinking a bit and applying some negatives:
CFrame.new(x ,y, z , r00, -r01, -r02, -r10, r11, r12, -r20, r21, r22);
Problem is that's a world space so it'll seem kinda arbitary, also we didn't move the position which we might as well do while we're at it. In short here's our final outcome:
function reflect(cf, mirror) -- get components in object space local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = mirror.CFrame:toObjectSpace(cf):components(); -- reflect in object space and convert to world space return mirror.CFrame:toWorldSpace(CFrame.new(-x ,y, z , r00, -r01, -r02, -r10, r11, r12, -r20, r21, r22)); end;
You could prob do it with vectors alone via the dot/cross product but I haven't tried that yet.
Sorry for the long wait! |
|
|
| Report Abuse |
|