Isometric Movement in Javascript In the DOM
- by deep
I am creating a game using Javascript. I am not using the HTML5 Canvas Element.
The game requires both side view controlles, and Isometric controls, hence the movementMode variable.
I have got the specific angles, but I am stuck on an aspect of this.
https://chillibyte.makes.org/thimble/movement
function draw() {
if (keyPressed) {
if (whichKey == keys.left) {
move(-1,0)
}
if (whichKey == keys.right) {
move(1,0)
}
if (whichKey == keys.up) {
move(0,-1)
}
if (whichKey == keys.down) {
move(0,1)
}
}
}
This gives normal up, down , left, and right. i want to refactor this so that i can plugin two variables into the move() function, which will give the movement wanted.
Now for the trig.
/|
/ |
/ | y
/ |
/a___|
x
Take This Right angled Triangle.
given that x is 1, y must be equal to tan(a)
That Seems right.
However, when I do Math.tan(45), i get a number similar to 1.601.
Why?
To Sum up this question.
I have a function, and i need a function which will converts an angle to a value, which will tell me the number of pixels that i need to go up by, if i only go across 1. Is it Math.tan that i want? or is it something else?