Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] CFrame multiplication not working correctly?

Okay, so I have a position given in CFrame only. In this post, it will be labeled CFramePosition.

I want to multiply this by a number, so that any result CFrame is twice as far as the original CFramePosition. In this post, this number will be labeled Scale.

However, when I perform:

CFramePosition * CFrame.new(Scale,Scale,Scale)

the result is:

CFramePosition * CFrame.new(Scale,Scale,Scale) + CFrame.new(Scale,Scale,Scale)

Where is the last CFrame being added coming into the question? I don't have ANY addition being performed inside this CFrame math, so how is it being added to the equation?

Before you answer, I've already tried this:

(CFramePosition * CFrame.new(Scale,Scale,Scale)) - CFrame.new(Scale,Scale,Scale)

The result asks for the last subtraction to be done as a Vector3, not a CFrame, and when I make the change, I get... part of what I want.

The position, without any rotation, is correct. However, as soon as I rotate CFramePosition, it rotates on an offset point below CFramePosition.


Here's my code, to show that I'm not going insane:

local function updateCamera()
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = CFrame.new(script.Parent.CameraBase.Position.X,script.Parent.CameraBase.Position.Y + (userHeight * (vrScale/2)),script.Parent.CameraBase.Position.Z)
	cpos.CFrame = camera.CFrame
	camera.HeadScale = vrScale
end

local function updateArm(hand, cframe)
	hand.CFrame = cframe
end

UIS.UserCFrameChanged:connect(function (type, cf)
	if type == Enum.UserCFrame.Head then
		updateCamera()
	elseif type == Enum.UserCFrame.LeftHand then
		if not hands[1] then print("LEFT HAND NOT FOUND") else
		updateArm(hands[1], (camera.CFrame * (cf * cfScale)))
		end
	elseif type == Enum.UserCFrame.RightHand then
		if not hands[2] then print("RIGHT HAND NOT FOUND") else
		updateArm(hands[2], (camera.CFrame * (cf * cfScale)))
		end
	end
end)

The only addition I perform in this code is when I set the camera CFrame (which works fine). I am getting a weird extra addition when I perform the multiplication inside the UserCFrameChanged function (lines 17 and 21).

2 comments

0

I'm not sure if this helps, but when it comes to multiplying two CFrames, you're actually doing addition on the values.

0

The problem is that I'm both multiplying, and adding the values somehow. When I perform said math and move my controllers, the offset parts move exactly as far as I need them to -- The problem is in the name: "the offset parts".

1 answer

I found the answer after lots of trial and error regarding CFramePosition.p...

local scaledLeftHandCFrame = CFrame.new(LeftHandCFrame.p*(vrScale-1))*LeftHandCFrame
local scaledRightHandCFrame = CFrame.new(RightHandCFrame.p*(vrScale-1))*RightHandCFrame
local LeftCFrame = camera.CFrame * scaledRightHandCFrame
local RightCFrame = camera.CFrame * scaledLeftHandCFrame

This discussion is preserved as it was. New answers, comments, and votes are closed.