Now my issue is when I move, its really fast and the speed doesnt change when I change the number (-1)
And when I remove normalize, the player just flies away faster than light and leaves the skybox
Also, if theres a better way to make character movement please tell me
getDeltaTime will return the time in miliseconds between frames, which would be at least around 16 for a 60FPS scene. If your scene is small, this will surely make your player move really fast. What you probably want instead is to define some velocity for the player, and perform the necessary unit conversions for it to make sense. For example, assuming that the units in your scene represent meters, if you want your player to move at 1 km/h, that is 1000m/360000ms = 0.0027m/ms.
You also don’t want to add the delta to the movement direction, as that will change the movement direction vector itself. What you want instead is to scale the normalized direction vector by that delta.
Taking the above two points into account, the modified code would look like this:
var speed = 0.0027;
moveDir.normalize();
moveDir.scaleInPlace(speed * engine.getDeltaTime());
player.moveWithCollisions(moveDir);
As Sergio mentioned, if you can share a playground, we can take a better look at your code.
The diagonal movement being fast is a result of how you apply the movement vector. If you move only on one direction, let’s say x, the vector is: (s, 0, 0), where s is your speed. If you move in x and y at the same time (so, diagonal movement), the vector is (s, s, 0). The thing is, these vectors have different lengths, so they represent different speeds, the second one is faster. If you want the character to move always at the same speed, no matter the direction, it’s good to start with a normalized vector, i.e, a vector of length 1. In the x direction, that would be (1,0,0), while in the xy diagonal, that would be (0.707, 0.707, 0) - not (1,1,0)!. Then, you scale the normalized vector by the speed s, and since the starting length is 1, scaling by s would make its length s! Then, all directions will have the same length, which means they also have the same speed.
Hope this explanation makes sense, please let me know if not.
Theyre cleared when I let go of the key, but when I hold the key theres multiple duplicates of the key
It wont matter though because the thing that checks for keys uses Array.includes()