Unit movement Vector3

Hi there, I was trying to make a custom movement system but I don’t know how to make the movement/move direction a unit vector. Vector3.Unit works but I don’t know how to implement it in my case:

local Keys = {
		Horizontal = Input.GetKey("D","Left") - Input.GetKey("A", "Right"),
		Vertical = Input.GetKey("W","Up") - Input.GetKey("S","Down")
	}
	local Force = (CameraLookVector * Keys.Vertical + CameraRightVector * Keys.Horizontal) * Speed

This is the code (shortened) but when moving diagonally, the player moves way faster than in any single direction which I do not want.

Thanks. (This question is probably answered in a different post(s) but I can’t find them.)

Don’t use Keys.Vertical * Keys.Horizontal. Just find a number that works so the movement is always with the same force.

I don’t understand.
The reason I use Keys.Horizontal and vertical is to get the direction of the player. The GetKey function returns a value of 0,1.
If I pressed W or Up then it would say one in Vertical, and S would say -1. (Pressing both gives 0 and neither is still 0)

Is Force a Vector3?

Try:

local Force = (CameraLookVector * Keys.Vertical + CameraRightVector * Keys.Horizontal).Unit * Speed

Thanks, I just used a Humanoid.MoveDirection instead which automatically does this for you. :+1:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.