Is there any way I can obtain the move vector in the direction of the camera (like a look vector)? For example, if I press W and D, I want to obtain a unit vector that is 45 degrees from the look vector of the camera. Does any know how to do it?
I am not sure what you are saying, but if you want to get the current lookVector of the camera and add 45 degrees to it on the x direction. You can do this:
local camera = game.Workspace.CurrentCamera
local desiredLookVector = (camera.CFrame * CFrame.Angles(math.pi/4, 0, 0)).lookVector
The simple answer is cframe:vectorToWorldSpace(vector)
, but I suspect this doesn’t solve your problem. What are you actually trying to achieve?
@ur_famous Thanks for the reply however I don’t really want to rotate the lookvector. Thanks for the reply though!
@blobbyblob I managed to solve the problem. Your answer is part of the solution to my problem. What my initial problem was was that I wanted a unit vector similar to a camera look vector but is 45 degrees to the look vector. Its quite hard to explain so I really apologise for my poor elaboration. I’m still not very sure about how should I describe it but blobbyblob was close. Thanks for your reply! I’ll mark yours as the solution because it best represents the answer.
I know this is incredibly late, but I was just working on a movement system and came up with this solution. I hope it helps anybody else who comes across this thread. Since it didn’t seem like anybody elaborated the full solution, I’ve decided to write my thought process down here.
I created a table of “direction vectors,” of which I summed up based on which keys are pressed.
Looks like this:
(I know they’re CFrames, not vectors, but you get the point)
Each of those are direction “vectors” that are simply added together when the keys are pressed. I then took the camera’s CFrame (for my use case, I canceled out its X/Z rotations and just cared about the rotation about the Y-axis) and used :VectorToWorldSpace(directionVector)
on it to rotate that position relative to the camera. Then, I added that world-relative position offset from the origin of the world (see: all those 0s in the CFrames) to the position of the character. Voila, you have your camera-relative point translated from the world origin to your character’s position!
Edit: Ignore those speedMultipliers, they’re just a remnant of other stuff I was trying out.