Jump to content

Move RTS ArcRotateCamera


Nyanta
 Share

Recommended Posts

Hi,

 

currently, i've problems to move the ArcRotateCamera correctly around. I came up with this code:

translation = BABYLON.Vector3.TransformNormal(translation, this._camera.getWorldMatrix());translation.y = 0;this._camera.target.addInPlace(translation);

but the translation in z direction is slower, since the camera is tilted (i need to set translation.y to zero after transformation). Is there a good way to just rotate my desired translation around the y-axis in dependent to the alpha of the ArcRotateCamera?

 

Kind Regards,

Chris

Link to comment
Share on other sites

Hey Carlos,

 

if i could you a simple example, it wouldn't be necessary to ask for help, since i would solve my own problem :D

But i could show you the behavior:

 

http://area51.lypster.net:8888/

 

Here i'm using the ArcRotateCamera, you can move around with W,A,S,D and rotate with Q and E.

If you move around you recognize that the forward and backward movement is slower than left and right movement.

 

The reason is the transformation i need to do in order to translate in view direction:

//        // The keyboard movement logic        //        if (Keyboard.IsKeyDown(Key.W)) {            translation.z += (deltaTime);        }        if (Keyboard.IsKeyDown(Key.S)) {            translation.z -= (deltaTime);        }        if (Keyboard.IsKeyDown(Key.D)) {            translation.x += (deltaTime);        }        if (Keyboard.IsKeyDown(Key.A)) {            translation.x -= (deltaTime);        }        translation = BABYLON.Vector3.TransformNormal(            translation, this._camera.getWorldMatrix());        translation.y = 0;        this._camera.target.addInPlace(translation);

I don't get it how i can transform the translation vector so that forward and backward is the same as the left and right speed.

 

Kind Regards,

Chris

Link to comment
Share on other sites

For me, it's actually very hard to notice the difference (and I'm still not sure there is an actual difference, it might be psychological). That being said, it seems that you can achieve what you want simply by scaling your movement.

 

Here's an untested example:

//// The keyboard movement logic//var scaleX = .9;var scaleZ = 1.2;if (Keyboard.IsKeyDown(Key.W)) {    translation.z += (deltaTime * scaleZ);}if (Keyboard.IsKeyDown(Key.S)) {    translation.z -= (deltaTime * scaleZ);}if (Keyboard.IsKeyDown(Key.D)) {    translation.x += (deltaTime * scaleX);}if (Keyboard.IsKeyDown(Key.A)) {    translation.x -= (deltaTime * scaleX);}translation = BABYLON.Vector3.TransformNormal(    translation, this._camera.getWorldMatrix());translation.y = 0;this._camera.target.addInPlace(translation);

That example is mostly just illustrating the point; I wouldn't suggest having two variables when one can do the job just as easily.

Link to comment
Share on other sites

Hi Macguyvok,

 

i already found a solution for my problem (just normalize the translation so that the distance is 1.0 ) :)

thats why, you didn't notice a difference in the movement anymore (buildserver already deployed the new version).

 

Kind Regards,

Chris

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...