Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Force a model to a specific position without collide?

Asked by
Nickoakz 231 Moderation Voter
10 years ago

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

Log in to vote
1
Answered by 10 years ago

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.

Ad
Log in to vote
0
Answered by 10 years ago
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.)

0
This worked. Thank you. This should have been added to the wiki, since I use it A LOT. Nickoakz 231 — 10y
0
You should totally click that green check for me. ;) TheGuyWithAShortName 673 — 10y
0
I thought this worked, until it keeps moving like 100 units away from where I want it to be. Nickoakz 231 — 10y
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). TheGuyWithAShortName 673 — 10y
Log in to vote
-1
Answered by 10 years ago

idgaf

Log in to vote
-3
Answered by 10 years ago
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()
0
This moved my model to the position, yes. But it moved it with collide, noes. Nickoakz 231 — 10y

Answer this question