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

lookVector cannot be assigned to?

Asked by
u_g 90
10 years ago

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)  
0
p is defined as Instance.new("Part"), by the way. u_g 90 — 10y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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)
0
What does the "from" and "to" mean? u_g 90 — 10y
0
Nevermind. u_g 90 — 10y
Ad

Answer this question