Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (604) Games in Android Showcase (171) games submitted by our members Games in WIP (654) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Free-flying camera Y axis movement too fast, is tangent vector calc wrong?  (Read 596 times) 0 Members and 1 Guest are viewing this topic.
pixelprime

Junior Devvie

Medals: 3

 « Posted 2013-02-20 10:33:23 »

Hi All,

I've written a camera class to handle FPS-style movement throughout the game world, but for some reason I don't seem to be traveling the correct distance along the Y axis when pointing in that direction. Here's the code that handles the calculation of 'moving forward' along the current vector:

 1  2  3  4  5  6  7  8  9  10 `protected void moveForward(float distance)   {      // track value (for debugging)      lastMoveForward = distance;            speedX -= (distance * (float)Math.sin(Math.toRadians(yaw)));      speedZ += (distance * (float)Math.cos(Math.toRadians(yaw)));              if (flyMode) { speedY += distance * (float) Math.tan(Math.toRadians(pitch)); }   }`

Some quick code notes:
yaw: a value between 0-359
pitch: a value clamped between -80 (looking down) and 80 (looking up)
speedX/Y/Z: values that are added to the camera's X, Y and Z positions respectively, then zeroed-out ready for the next tick.

Moving along the X and Z axes (when looking along those axes) works beautifully. The distance travelled is ~4 units per second.

However, when flyMode is switched on (for a free-flying camera), and looking up or down, the distance travelled is vastly different - more like 20-30 units per second.

Am I calculating the speed increment along the Y axis totally wrong? Or maybe a combination of them all?

Many thanks for any help anyone can offer. I'm already learning how tremendously resourceful this community can be : )
DazKins
 « Reply #1 - Posted 2013-02-20 12:23:12 »

You should not be using Math.tan() to calculate the new y value, You should be using Math.sin

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
pixelprime

Junior Devvie

Medals: 3

 « Reply #2 - Posted 2013-02-20 13:10:40 »

That's perfect! Thanks for your help!
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 bilznatch (22 views) 2015-08-04 11:03:17 SHC (39 views) 2015-08-01 03:58:20 Jesse (24 views) 2015-07-29 04:35:27 Riven (45 views) 2015-07-27 16:38:00 Riven (25 views) 2015-07-27 15:35:20 Riven (27 views) 2015-07-27 12:26:13 Riven (18 views) 2015-07-27 12:23:39 BurntPizza (41 views) 2015-07-25 00:14:37 BurntPizza (51 views) 2015-07-24 22:06:39 BurntPizza (33 views) 2015-07-24 06:06:53
 theagentd 50x wessles 49x basil_ 33x KaiHH 26x orangepascal 21x Riven 21x ags1 17x mooman219 17x bornander 16x KudoDEV 13x CelestialCreator 11x klaus 11x princec 11x pquiring 11x Jesse 9x israelg99 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org