You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firstly, love the work that is happening on this project
So I just cloned the project and took a look at the example project and there seems to be some oversight in the gameplay programming
When moving diagonally the player moves faster than moving horizontally, usually this is because the input vector is not normalized.
I dug a bit deeper into the code and found where directions are being assigned but it looks like this would only deal with 4 directional movement from what I can see...
So it seems like the movement for x and y axis would be additional and therefore the length of the directional vector is wrong when moving diagonally.
Anyway! The way that the direction is calculated is fine but the fact that is added together for x and y, FORGETABOUTIT you don't want to do that.
privatedirectionToAngle(direction: number): number {constangle=(direction<2 ? +direction+2 : direction-2)*90returntoRadians(angle)}/** @internal */defineNextPosition(direction: number,deltaTimeInt: number): Vector2d{constangle=this.directionToAngle(direction)constcomputePosition=(prop: string)=>{returnthis.position[prop]+this.speed*deltaTimeInt*(Math.round(Math[prop=='x' ? 'cos' : 'sin'](angle)*100)/100)}// If it's greater than 1, round value to reduces bandwidthconstx=this.speed<1 ? computePosition('x') : round(computePosition('x'))consty=this.speed<1 ? computePosition('y') : round(computePosition('y'))returnnewVector2d(x,y,~~this.position.z)}
What you want to do is get the player input as a vector2. If the player or npc is pressing up or wants to move up the vector2 is (0,-1) if up left its (-1,-1) if down right its (1,1) etc then you can normalize this vector with a function like this:
That way the length of the vector will be normalized. Then you can multiply that vector by the speed and deltatime and bingo, you have correct diagonal movement consistent with the speed of horizontal movement.
The text was updated successfully, but these errors were encountered:
Firstly, love the work that is happening on this project
So I just cloned the project and took a look at the example project and there seems to be some oversight in the gameplay programming
When moving diagonally the player moves faster than moving horizontally, usually this is because the input vector is not normalized.
I dug a bit deeper into the code and found where directions are being assigned but it looks like this would only deal with 4 directional movement from what I can see...
So it seems like the movement for x and y axis would be additional and therefore the length of the directional vector is wrong when moving diagonally.
Anyway! The way that the direction is calculated is fine but the fact that is added together for x and y, FORGETABOUTIT you don't want to do that.
What you want to do is get the player input as a vector2. If the player or npc is pressing up or wants to move up the vector2 is (0,-1) if up left its (-1,-1) if down right its (1,1) etc then you can normalize this vector with a function like this:
That way the length of the vector will be normalized. Then you can multiply that vector by the speed and deltatime and bingo, you have correct diagonal movement consistent with the speed of horizontal movement.
The text was updated successfully, but these errors were encountered: