As I was editing jmargh's arm cannon, I noticed that trying to edit the projectile's lookVector resulted in an error, saying "lookVector cannot be assigned to". I don't know what's wrong with the code, please help. Here's the part that changes the lookVector:
p.CFrame.lookVector = Vector3.new(0, 0, 0)
You cannot set the lookVector
of a CFrame, since it's read-only.
Since a CFrame's orientation is defined uniquely by two orthogonal vectors, setting one of them would result (usually) in an invalid second one (they would no longer be orthogonal); that is the reason this operation is not allowed.
Besides this, a lookVector can never be the 0 vector. lookVector
is always a unit vector. The default orientation's lookVector
is (0,0,-1)
You can construct a new CFrame pointing in a particular direction using the two-Vector3 CFrame.new
constructor:
p.CFrame = CFrame.new( p.Position, p.Position + Vector3.new(0,0, -1 )); -- CFrame.new( lookingFrom, lookingAt ) -- [Vector3] lookingFrom (p.Position to keep it at same place) -- [Vector3] lookinAt (p.Position + whatever direction for it to face)