I'm trying to translate and scale a 2D space from world space to camera space with my character in the center. Adding in the scaling is tripping me up.

Here's what I've got so far, without the scaling (JavaScript, but it doesn't really matter)

function transform(object, my_character) {
    var relative_x = object.x + window_width/2 - my_character.x;
    var relative_y = object.y + window_height/2 -  my_character.y;
    return [relative_x, relative_y]

What I don't understand is what to apply a scaling factor to? if I want to make everything half as small, do I multiply the scaling factor to the object.x and my_character.x?

The other piece is that I can't do special checks to see if object === my_character because of the game type (Agar.io clone). The character X & Y coordinates are occasionally averages of all the blob's positions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.