this happens
robloxapp-20221112-1630362.wmv (2.1 MB)
Any errors?
no, nothing shows up, it may be because you multiplied it by 0?
Multiplying a Vector3 will cause it to dynamically add and subtract. I am not sure what the problem is. Is the model anchored?
no, im pretty sure multiplying works with cframes only
Try changing * to +, if you think that.
now i want it to actually correctly offset
Hmm, maybe use cam.CFrame.LookVector instead of position? And, multiply it by around 10 instead of adding a Vector3.
okay i found a documentation about it, and i found something that works, but the rotation still changes.
but i think this is 100% easier to edit
local pos = cam.CFrame + cam.CFrame.LookVector * 5
model:PivotTo(pos)
Change that to cam.CFrame.Position
.
And then of course recast the vector as a CFrame value, using CFrame.new
okay it works! (For people that are too searching for the answer)
i changed the method a bit so now it works!
local pos = CFrame.new(cam.CFrame.Position) + cam.CFrame.LookVector * 5
model:PivotTo(pos)
to include a custom rotation i did this
local pos = (CFrame.new(cam.CFrame.Position) + cam.CFrame.LookVector * 5) * CFrame.Angles(20,10,5)
model:PivotTo(pos)
–fixed (=
Thank you, everyone who helped/tried to help me! Without yall, it probably would have took me a few more days to figure it out!
yeah thats what i did right now
We’ve definitely got the algorithm down, but I have a few suggestions to make things a bit more efficient.
If the rotation is going to be constant, we can define that beforehand (keep in mind that CFrame.Angles uses radians and not degrees). Then, instead of doing all this recasting and multiplication, we can simply use CFrame.fromMatrix to build the ideal CFrame from each of the vectors.
--cached
local Rotation = nil
do
local RotationCF = CFrame.Angles(math.rad(RotX), math.rad(RotY), math.rad(RotZ))
Rotation = {RotationCF.XVector, RotationCF.YVector, RotationCF.ZVector}
end
local Offset = 5
--active
local Position = CameraCFrame.Position + CameraCFrame.LookVector * Offset
model:PivotTo(CFrame.fromMatrix(Position, table.unpack(Rotation)))
I think that such optimizations might be worthwhile, as given the nature of this code, it will presumably be ran very quickly. This proposed method creates only a single new CFrame object per cycle, whereas the other approach takes three, and needlessly recalculates the rotational component.
Definitely putting this as a solution. But you could use mine if you want the code to be shorter (but not optimized), if that’s what you want.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.