Canvas script animation object move under diagonally

Please, I am reading:

This objects move all horisontally.

and I wonder how to get the object to move diagonally (angle 30, 45, 60 etc).
Does someone have a good beginners link or tutorial or example?
Many thanks inadvance.

To move object diagonally you should change both coordinates (X and Y).

object.x = object.x + speed;
object.y = object.y + speed;

This example will move object at an angle of 45 degrees
If you want another angle you have to use trigonometric functions:

var angle = 32; //angle in degrees
var angleRad = angle * (Math.PI/180); //angle in radians
object.x = object.x + speed * Math.cos(angleRad);
object.y = object.y + speed * Math.sin(angleRad);

MANY THANKS !!! I will think it over!!!

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