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

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

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

✓ Accepted answer

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

5 comments

2

It works! Thanks.

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?

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). 

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.

0

Thanks

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