Model Alignment

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make the Grey part align with the red part. (bottom of model)

  2. What is the issue? Include screenshots / videos if possible!
    I right now use bounding box and SetPrimaryCFrame/pivotto and end up with the grey part being under it yes, although it is not aligned with the true bottom.



(The red part was user generated, and is where the grey part which was script generated should be)

Graypart.CFrame = car.Position - car.CFrame.UpVector * car.Size.Y/2

The car is the hitbox of the car.
Im on phone please excuse me.

cant do model.position (car.position) as positon only works on parts nor model.cframe (car.cframe)

Like I said, the carPart is the hitbox

image

image

local function generatePart(size)
	local p = Instance.new("Part")
	p.Size = size
	p.Anchored = true
	p.Color = Color3.new(0.6,0.2,0.2)
	p.Parent = workspace
	
	return p
end

local function alignPart(model : Model)
	local hitbox = model.PrimaryPart
	local part = generatePart(Vector3.new(hitbox.Size.X,1,hitbox.Size.Z))
	
	part.CFrame = CFrame.new(hitbox.Position - (hitbox.CFrame.UpVector * (hitbox.Size.Y/2 + part.Size.Y/2)))*hitbox.CFrame.Rotation
end

alignPart(workspace.model)

I personally use this plugin for hitboxes:
image

If you don’t want the part to be generated, just replace the

part = generatePart(blah)

with your own part

My script working:
image

Hope this fixes your issues!
Have a nice day

-- Reference to the models you want to align
local modelToAlign = game.Workspace.ModelToAlign -- Replace "ModelToAlign" with the name of the model you want to align
local referenceModel = game.Workspace.ReferenceModel -- Replace "ReferenceModel" with the name of the model you want to align to

-- Check if both models exist
if modelToAlign and referenceModel then
    -- Set the position, rotation, and scale of the modelToAlign to match the referenceModel
    modelToAlign:SetPrimaryPartCFrame(referenceModel:GetPrimaryPartCFrame())
    modelToAlign:SetPrimaryPartCFrame(modelToAlign:GetPrimaryPartCFrame() * referenceModel:GetPrimaryPartCFrame():PointToWorldSpace(CFrame.new()))
    modelToAlign:SetPrimaryPartCFrame(CFrame.new(modelToAlign:GetPrimaryPartCFrame().p) * referenceModel:GetPrimaryPartCFrame())

    -- Optional: You can also set other properties like transparency or visibility if needed
    modelToAlign:SetPrimaryPartCFrame(referenceModel:GetPrimaryPartCFrame())
    modelToAlign.Transparency = referenceModel.Transparency
    modelToAlign.Visibility = referenceModel.Visibility
else
    warn("One or both models not found!")
end

Replace “ModelToAlign” and “ReferenceModel” with the actual names of your models. This script assumes that both models have a primary part set.

Adjust the script according to your specific requirements and the structure of your models.

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