Removing Y axis from VectorToWorldSpace

Hi!

I have made a custom movement script which uses this:

self.WishDir = CameraCFrame:VectorToWorldSpace(self.MoveVector)

What this does is takes the non-camerarelative self.MoveVector which tells the character where to go and, based off of the Camera’s CFrame, creates the camerarelative self.WishDir. This works well until you look up or down, where the character slows to a crawl.

A solution for this is to use the CFrame of the HumanoidRootPart, however this only works for first person view. All I really want to know is if it possible to get the CFrame of the camera except for the Y axis, so that the speed of the character’s movement doesn’t get affected by the Y angle the character is looking at

Any help is appreciated
Thanks

This is w/o y translation.

local withoutY = CFrame.new(CameraCFrame.X,0,CameraCFrame.Z) * -- translation component 
(CFrame.new(CameraCFrame.p):Inverse() * CameraCFrame) -- rotation component

If you need to remove Y orientation, see ToEulerAnglesXYZ function. then use them in a *

local X,Y,Z = CameraCFrame:ToEulerAnglesXYZ()
CFrame.Angles(X,0,Z)

kind of operation


What actually is WishDir. Is it a unit direction? like HumanoidRootPart.LookVector? Or is it the target position of the character? Why are you doing this movement approach specifically. More general info appreciated.

WishDir is a Vector3 property which is put into LocalPlayer.MoveFunction() in order to make the player move around. Without VectorToWorldSpace, the player moves in relation to the XYZ axes of the world, with VectorToWorldSpace the player moves in relation to the XYZ axes of the camera (so when you move the camera, the player moves too). For reference, self.MoveVector is not camera relative, i.e. it follows the XYZ angles of the world.

I’ve used it because I’ve taken this script, integrated it as best I can into Roblox’s own ControlModule so it works on all devices and then changed some stuff to make it do what I want better. All of the movement stuff is from that script as I haven’t changed any of it.

1 Like

Just tried it out, this works perfectly. Thanks!