object:PivotTo(Crame.new(result.Position + result.Normal) causes object to hover

Hey LG, any chance you could help us understand this a little better, as we want to use it on objects that are welded together, and other applications, too. But even after researching it (everywhere, api, youtube, forum, and of course tinkering with it ourselves) we can’t figure it out.

Especially these lines:

deployment:PivotTo(CFrame.new(result.Position, result.Position + result.Normal):ToWorldSpace(CFrame.new(0, 0, -deployment.Size.Z / 2)) * CFrame.Angles(math.rad(-90), math.rad(-90), 0))
		local x,y,z = script.Parent.Handle.CFrame:ToEulerAnglesXYZ()
		deployment.CFrame = deployment.CFrame * CFrame.Angles(0,y,0)

we understand the “pivot to” line, but what does ToWorldSpace do? especially in this application? I watched videos, and some of the videos said one thing, some other videos said the OPPOSITE… classic - the api doesn’t explain it.

Likewise, what’s “toeulerangles” do? Does it force the object to move on the world axis, as opposed to the objects local axis?

thanks much for any help. !

Certainly! Beginning of every Roblox Assistant response

ToWorldSpace basically just takes the object’s CFrame and moves it in studs based on that CFrame. (Why it’s called ToWorldSpace? Not sure, but it has to do with the complicated explanation of it) So basically, if I have a part that is facing forward and a part tilted awkwardly in every axis, and call :ToWorldSpace(CFrame.new(2,0,0)), both will move in their axis to the left two studs.

ToEulerAngles just returns a tuple (multiple variables defined at once, like when using success, error on pcall()) of the CFrame’s angles, in degrees (by default, CFrame angles are in radians). It’s pretty much the same as ToOrientation().

1 Like

Thank you for the help. Very useful - best !

1 Like

Hey we noticed something. If we want to put the deployable on something that has a Y rotation, it doesn’t work. How do I take the result.Instances Y rotation into account, so that the spike strip still is at 90 degrees to the character?

1 Like

I think we solved the problem of placing it on an object that has previously been rotated on the Y axis:

			local x,radHandleY,z = rootPart.CFrame:ToOrientation()
			local degHandleY = math.deg(radHandleY)
			local degBaseY = result.Instance.Orientation.Y --in degrees

			local degAdjustY = degHandleY - degBaseY
		if result.Instance.Orientation.Y ~= 0 and result.Instance.Orientation.Y ~= 180 and result.Instance.Orientation.Y ~= -180 then

			deployment:PivotTo(CFrame.new(result.Position, result.Position + result.Normal):ToWorldSpace(CFrame.new(0, 0,  -deployment.Size.Y/2)) * CFrame.Angles(math.rad(-90), math.rad(degAdjustY), 0))

		else
			deployment:PivotTo(CFrame.new(result.Position, result.Position + result.Normal):ToWorldSpace(CFrame.new(0, 0,  -deployment.Size.Y/2)) * CFrame.Angles(math.rad(-90), math.rad(-90), 0))
			deployment.CFrame = deployment.CFrame * CFrame.Angles(0,radHandleY,0)

		end

We don’t really know .why. it works like this. But we jiggered with it til it did.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.