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

How to get the CFrame.lookVector to the left, instead of from the front?

Asked by 9 years ago

I've been trying to make a space game, but the problem is that when I want to move my ship I just use .lookVector to get my velocity. But in order to use that to go left, is a problem. Anyone know a way to do this?

1 answer

Log in to vote
3
Answered by
XAXA 1569 Moderation Voter
9 years ago

Rotate the CFrame counterclockwise along its Y (vertical)-axis by 90 degrees, then get its .lookVector:

local part = script.Parent

local pushdirection = (part.CFrame * CFrame.Angles(0, math.pi/2, 0)).lookVector -- Gets the part's CFrame, rotates it 90 degrees (math.pi/2 radians) counterclockwise along its Y-axis so that faces the left, and then gets its lookVector.
local pushvelocity = 400

part.Velocity = pushdirection * pushvelocity
2
It works! Thanks. dudemanjude 10 — 9y
0
Could you not just get the rotational part of the CFrame and multiply it by Vector3.FromNormalId(face), where face is the NormalId Enum for the surface of a brick? Spongocardo 1991 — 9y
0
That wouldn't give the correct result. Yours would be the same as moving the part to (0, 0, 0) while keeping the rotation, and translating it one stud to its left. The front of the part would still be facing the same direction (and therefore the lookVector wouldn't change).  XAXA 1569 — 9y
0
If you want to use NormalIDs, CFrame.new(part.position, ( part.CFrame * CFrame.new(Vector3.FromNormalID("Left") ) ).p).lookVector should give the same result. XAXA 1569 — 9y
0
Thanks Firopense 0 — 3y
Ad

Answer this question