Sign in to follow this  
CyanPrime

Splitting this into a x and y point?

Recommended Posts

Alright, so I'm still trying to make my players movements relative to the camera. I got a good answer here:http://stackoverflow.com/questions/4321382?tab=votes#tab-top
But he ends it with: s(Jx x̂ + Jy ŷ)

So how can I turn that equation into a x and y?

Share this post


Link to post
Share on other sites
Each of the terms, x̂ and ŷ is a vector, each therefore having its own x and y components. So, basically, you have:

x̂ = <a, b, 0.0>

and

ŷ = <c, d, 0.0>

Where a, b, c, and d are just values that came out of the vector math shown in the other formulas in that post. a and b are the world/game space x and y components of the axis, x̂, pointing to the camera's right. If the player moves a units in the x direction and b units in the y direction, the player will have moved towards the right side of the camera without moving closer or further away. Similarly, c and d represent the world/game space x and y components of the axis, ŷ, pointing away from the camera. So if the player moves c units in x and d units in y, then the player would move away from the camera.

So, if you expand out that final equation using the formulas I've listed above, and separate into bits that represent movement in the world/game space x and y directions, you will get:

player_translation.x = s*Jx*a + s*Jy*c;
player_translation.y = s*Jx*b + s*Jy*d;

Notice how the player_translation.x equation refers to a and b, which were the world/game space x direction components of the two projected camera axes. Similarly the .y version refers only to b and d, which represented the y direction components of the two vectors.

Hope that helps!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this