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

Help with cframe angle! How to have it keep it's angle?

Asked by 6 years ago

Hello,

So I had some help with this Cframe script from another post. I am creating a firework and one of the fireworks is on an angle of 25 degrees. This script does not take that into account and just shoots it straight up. How would I make it so that it moves it up still with keep it's angle of 25 degrees?

Thanks.

Anthony

Model = script.Parent.Parent.Parent.Firework1
local StartPos = Model.PrimaryPart.CFrame --- this is where the model started 
local EndPos = StartPos + Vector3.new(30,0,0) -- this is where the model started moved up and over
for i = 0,30,0.1 do -- this says repeat between 0 and 1 for 0.1. So it will repeat 10 times. 0, 0.1 ,0.2... ect
Model:SetPrimaryPartCFrame(StartPos:Lerp(EndPos, i)) -- this returns a positiong between StartPos and EndPos. I is the increment between. So if i == 0.5 it will be the middle, i == 1 it will be the end i == 0 its the start
wait() 
end


1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago

Hmm maybe we can do this by recording the cframe that lerp gives us, take the vector3 of that and adding our own rotation

First let's get your lerp here, also your not listening to the own comments added to this script, the for loop has to be between 0 and 1.

local Model = script.Parent.Parent.Parent.Firework1
local StartPos = Model.PrimaryPart.CFrame
local EndPos = StartPos + Vector3.new(30,0,0)

for i = 0,1,0.1 do wait() 
    local cf = StartPos:Lerp(EndPos, i))
end

so i removed the comments, fixed the between 0 and 1 and also i cf = the lerp cframe.

Now let's set the primarypart's cframe with the vector3 of the lerp but adding our own direction

local Model = script.Parent.Parent.Parent.Firework1
local StartPos = Model.PrimaryPart.CFrame
local EndPos = StartPos + Vector3.new(30,0,0)

for i = 0,1,0.1 do wait() 
    local cf = StartPos:Lerp(EndPos, i))
    Model:SetPrimaryPartCFrame(cf*CFrame.Angles(math.rad(25),0,0))
end

You may want to experiment and change what's inside CFrame.Angles to your desired angle, right now its rotating the x axis of the primarypart to 25 degrees but i don't really have your model

Ad

Answer this question