Isometric Movement in Javascript In the DOM

Posted by deep on Game Development See other posts from Game Development or by deep
Published on 2013-11-11T19:40:00Z Indexed on 2013/11/11 22:16 UTC
Read the original article Hit count: 312

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?

© Game Development or respective owner

Related posts about math

Related posts about JavaScript