Why does multiplying a CFrame by another CFrame give me a slight offset to the right?

Hi,

I’m currently working on finishing up my wall placement system but I’m experiencing a small issue where multiplying a CFrame by another CFrame gives me a very slight offset when filling in the gap at the end of the wall:

As you can see here, the part is shifted ever so slightly to the right, it represents the edge at the end of the wall
image
To generate the part:

outer1.CFrame * CFrame.new(-outer1.Size.X / 2, 0, outer1.Size.Z / 2)

To get the correct position, I have to do this:

outer1.Position + (outer1.CFrame.LookVector * (outer1.Size.Z / 2)) + (outer1.CFrame.RightVector * (outer1.Size.X / 2))

Which gives me this, note the edge at the very top of the sphere ends where the wall ends:
image

Can someone explain why this is happening? I would pass it off as a floating point error but it’s something actually visible and would have an impact on the user and the system as a whole.

Thanks!

I think if you could send some template file that presents this problem, it would be easier to investigate. I tried on reproducing but I can’t get the same result.

Sure. Give me a bit as I have to narrow it down quite a bit.

Alright here’s the repro:
wallthing.rbxl (43.5 KB)

Press run and you’ll see these two points appear on the generated wall, the green one is the intended behaviour whereas the red one is the unintended behaviour:

Thanks , will check out soon! ^^

1 Like

I’ve given it a look, I can’t notice any mistakes. However the entire code is pretty big and I could be missing some context.

I think it would be useful if you could repro it to its minimal form, this way you will also understand the exact reason this takes place. I’m assuming it’s related to the logic of your script, since if you take the very minimal example where you just place a part in a wall, it always works finely (using the code example you gave):

Sorry I couldn’t be of help :frowning:

Yeah that’s what happened to me as well, I tried just placing a part and creating the new parts at the proper corners and they placed correctly. It isn’t a big deal though since using RightVectors and LookVectors works fine, just a bit inconvenient especially because I don’t know why it’s happening.

I’ll check again tomorrow tho, it’s 4 am so it’s probably just brain fog.

In the docs:
Returns the composition of two CFrames.
Proceeding CFrames are offset in relative object space by preceding CFrames when multiplied together.

This explains it as you probably have a position value which both add up together when you multiply the CFrame.

I manage to get it the same, but why were you using outer2 values and comparing them to outer 1? Outer2.CFrame seems to be a completely different wall

	if intersectionFromW2.X > 0 then
		print("Hello2")
		outer2.CFrame *= CFrame.new(diff / 2, 0, 0)
--debug the CFrame before any transformation, just the position
		--outer2FillVertex = outer2.Position --found out different wall than outer1.Position
--Before
		--outer2FillVertex = outer2.Position + (outer2.CFrame.LookVector * (outer2.Size.Z / 2)) + (outer2.CFrame.RightVector * (outer2.Size.X / 2))
--After
		outer2FillVertex = outer1.Position + -(outer1.CFrame.LookVector * (outer1.Size.Z / 2)) + -(outer1.CFrame.RightVector * (outer1.Size.X / 2))

If you compare the outer1.Position and outer2.Position, it’s a different wall with a different CFrame?

1 Like

Multiplying cframes actually just adds them. If you want to multiply them you will have to multiply each different value instead of it all at once

Yeah that was it, I don’t know how I didn’t realize that earlier. Thanks!