Skip to content

Add optional rotation support to createColCuboid#4732

Open
PrimelPrime wants to merge 2 commits intomultitheftauto:masterfrom
PrimelPrime:feat/createColCuboid-rot
Open

Add optional rotation support to createColCuboid#4732
PrimelPrime wants to merge 2 commits intomultitheftauto:masterfrom
PrimelPrime:feat/createColCuboid-rot

Conversation

@PrimelPrime
Copy link
Contributor

Summary

Adds optional rotation support to createColCuboid. The cuboid now stores a ZXY Euler rotation and uses OBB hit detection if a rotation is set otherwise returns to default AABB hit detection.

local col = createColCuboid(x, y, z, sx, sy, sz [,rx, ry, rz])

Motivation

Cuboids previously only supported axis-aligned bounding boxes (AABB), making it impossible to accurately represent rotated structures without workarounds e.g. overscaling cuboids or using colspheres which arent accurate enough in certain use cases.

Test plan

local radius = 15
local width, depth, height = 5, 5, 5
local px, py, pz = getElementPosition(localPlayer)
local cols = {}

for i = 0, 7 do
	local angleDeg = i * 45
	local angleRad = math.rad(angleDeg)

	local midX = px + radius * math.sin(angleRad)
	local midY = py + radius * math.cos(angleRad)

	local colX = midX - width * 0.5
	local colY = midY - depth * 0.5
	local colZ = pz - height * 0.5 + 1.7

	cols[i + 1] = createColCuboid(colX, colY, colZ, width, depth, height, 0, 0, angleDeg)
end

addEventHandler("onClientColShapeHit", root, function(theElement, matchingDimension)
	if theElement == localPlayer then
		outputChatBox("In")
	end
end)

addEventHandler("onClientColShapeLeave", root, function(theElement, matchingDimension)
	if theElement == localPlayer then
		outputChatBox("Out")
	end
end)

addCommandHandler("rotcol", function(_, deg)
	deg = tonumber(deg) or 45
	for _, col in ipairs(cols) do
		_, _, rz = getElementRotation(col)
		setElementRotation(col, 0, 0, rz + deg)
	end
end)

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

@PrimelPrime PrimelPrime requested a review from a team as a code owner February 28, 2026 03:42
Comment on lines +7510 to +7511
CVector vecRotationRadians = vecRotation;
ConvertDegreesToRadians(vecRotationRadians);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it takes the vector by reference, what’s the point of creating a new vector?

SizeChanged();
}

void GetRotationRadians(CVector& vecRotation) const override { vecRotation = m_vecRotation; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noexcept

}

void GetRotationRadians(CVector& vecRotation) const override { vecRotation = m_vecRotation; }
void SetRotationRadians(const CVector& vecRotation) override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noexcept

Comment on lines +75 to +77
const float cx = cosf(rx), sx = sinf(rx);
const float cy = cosf(ry), sy = sinf(ry);
const float cz = cosf(rz), sz = sinf(rz);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use std::cosf, std::sinf

Comment on lines +42 to +44
const float cx = cosf(rx), sx = sinf(rx);
const float cy = cosf(ry), sy = sinf(ry);
const float cz = cosf(rz), sz = sinf(rz);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use std::cosf, std::sinf

@FileEX
Copy link
Member

FileEX commented Feb 28, 2026

Don’t you want to add this argument for the server side as well? Currently, this PR only adds the ability to set the rotation on the client side.

@FileEX FileEX added the enhancement New feature or request label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants