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

Force a model to a specific position without collide?

I have this car spawner with the car in game.ServerStorage. The only problem is, that the MoveTo function does not move the car to the position to spawn it.

ction GenerateCar()
--pcall(function() LastCar:Destroy() end)
script.Parent.Gen.BillboardGui.Frame.Visible=true
script.Parent.Gen.BillboardGui.Frame.TextLabel.Text="Covering Area."
local clone=game.ServerStorage.Car:clone()
clone:MoveTo(script.Parent.Cover.Position)
wait()

Once the car starts to appear, it starts spawning in where it was cut and pasted to game.ServerStorage.

Any ways to c-frame models?

4 answers

First off, I would recommend making sure you're parenting the car (which you do not appear to be doing ;P). Second off, here's a script that should CFrame models nicely:

function scan(v, t) -- This is called a recursive function
	for i, v in pairs(v:GetChildren()) do
		if (v:IsA("BasePart")) then
			table.insert(t, v)
		end

		scan(v, t)
	end
end

function cframeModel(model, basePart, cframe) -- basePart will have the exact same CFrame as "cframe". Other parts will be moved around it.
	local parts = {}
	scan(model, parts) -- This will update the parts table... tables are awesome!

	for i, part in pairs(parts) do
		print("Doing for part", part:GetFullName())

		if (part ~= basePart) then
			local dist = basePart.CFrame:inverse() * part.CFrame
			part.CFrame = cframe * dist
		end
	end

	basePart.CFrame = cframe
end

cframeModel(game.Workspace.Model, game.Workspace.Model.BasePart, CFrame.new(0, 10, 0) * CFrame.Angles(0, math.rad(90), 0)) -- An example of how to use this

Note that basePart will have the exact same CFrame as cframe. Other parts will be moved around it accordingly.

model:TranslateBy(Vector3.new(0,1,0))

That will move the Model the distance specified by the Vector3. It works just like CFrame too. (in the way that it goes inside of things.)

4 comments

0

This worked. Thank you. This should have been added to the wiki, since I use it A LOT.

0

You should totally click that green check for me. ;)

0

I thought this worked, until it keeps moving like 100 units away from where I want it to be.

0

I don't think you understand how it works. model:TranslateBy(Vector3.new(0,10,0)) would move it 10 studs up from it's current position. It would NOT move it to the position (0,10,0).

function GenerateCar()
--call (function() LastCar:Destroy() end)
script.Parent.Gen.BillboardGui.Frame.Visible=true
script.Parent.Gen.BillboardGui.Frame.TextLabel.Text="Covering Area.."
clone=game.ServerStorage.Car:clone()
clone:MoveTo(Vector3.new(script.Parent.Cover.Position))
wait()

1 comment

0

This moved my model to the position, yes. But it moved it with collide, noes.

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