Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

lookVector cannot be assigned to?

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)	

1 comment

0

p is defined as Instance.new("Part"), by the way.

1 answer

✓ Accepted answer

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)

2 comments

0

What does the "from" and "to" mean?

0

Nevermind.

This discussion is preserved as it was. New answers, comments, and votes are closed.