The direction movement of any 2d environment can be decomposed into the movement in the x and y directions. The unit distance of the object movement, how much the x and y components need to move is the key to how to determine the direction of movement. As shown below (w3c coordinate system)
As can be seen from the figure,
sinθ = vY / 1,
cosθ = vX / 1,
The same goes for extending to 360 degrees.
Therefore, the unit moving distance in the x direction is cosθ, and the y direction is sinθ. Coupled with the motion parameter speed, the following js statement can be used in the code:
vx = Math.cos(angle * Math.PI / 180) * speed
xy = Math.sin(angle * Math.PI / 180) * speed