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

Is it possible to lerp a model? If so, how?

Asked by
LawlR 182
6 years ago

What I want to happen is when a character presses 'M' then a model will slowly come up from the ground next to the character. I can do the pressing M part but I'm not sure how to move the model smoothly.

2 answers

Log in to vote
0
Answered by 6 years ago

Basic lerp methods:

cframeoffset = CFrame.new()

game:GetService("RunService").RenderStepped:Connect(function()
    cframeoffset = cframeoffset:lerp(target CFrame, alpha) --when approaching its target slows down, e.g: 0, 0.5, 0.75, 0.875 etc...
    cframeoffset = start CFrame:lerp(target CFrame, alpha) --travels at a steady speed, e.g: 0.1, 0.2, 0.3, 0.4 etc...
end)

And to lerp the model:

local model = path.to.model
game:GetService("RunService").RenderStepped:Connect(function()
    --method you used to set the cframe
    model:SetPrimaryPartCFrame(cframeoffset)
end)

I hope this helps.

0
Yeah, I haven't started lerping because when I spawn the model, it spawns sideways. I posted another question about that, but no one has answered it yet. LawlR 182 — 6y
0
just use angles to rotate the model, cf * CFrame.Angles(rad(n), rad(n), rad(n)) abnotaddable 920 — 6y
0
Pretty sure I did that and it didn't work. LawlR 182 — 6y
0
Okay the orientation worked. Decided not to lerp though. LawlR 182 — 6y
Ad
Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

You can set the model's Model.PrimaryPart property, and afterwawrds use the Model:SetPrimaryPartCFrame() method and the CFrame:lerp() method to do this. I'd caution you that you should weld the parts of your model to the primary part to prevent rounding errors from slowly distorting your model as it moves over time. (See here: https://devforum.roblox.com/t/setprimarypartcframe-gradually-offsets-component-parts/16041)

Answer this question