Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (710) Games in Android Showcase (212) games submitted by our members Games in WIP (784) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 basic forumula help?  (Read 1143 times) 0 Members and 1 Guest are viewing this topic.
CyanPrime
 « Posted 2010-05-08 16:49:14 »

Some reason this formula doesn't guide "angle" to "(float) Math.toDegrees(Math.atan2(x - target.x, -(y - target.y)))"
Can someone tell me what I'm doing wrong?

 1  2  3  4  5  6  7  8  9  10 `if(angle > (float) Math.toDegrees(Math.atan2(x - target.x, -(y - target.y))) &&             angle <= -((float) Math.toDegrees(Math.atan2(x - target.x, -(y - target.y)))))            angle -= handleing;                  else if(angle < (float) Math.toDegrees(Math.atan2(x - target.x, -(y - target.y))) &&                angle > -((float) Math.toDegrees(Math.atan2(x - target.x, -(y - target.y)))))               angle += handleing;                  x -= Math.sin(Math.toRadians(angle)) * speed;         y += Math.cos(Math.toRadians(angle)) * speed;`
Riven

« JGO Overlord »

Medals: 1259
Projects: 4
Exp: 16 years

 « Reply #1 - Posted 2010-05-08 17:26:09 »

it's atan2(y, x) not atan2(x, y)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Hansdampf

Senior Devvie

Projects: 3

too offending?

 « Reply #2 - Posted 2010-05-08 17:32:57 »

besides the x/y swap,  your code hurts my eyes. Why don't you just write

 1  2  3  4  5  6  7 `      float a = (float) Math.toDegrees(Math.atan2(x - target.x, -(y - target.y)));      if (angle > a && angle <= -a)         angle -= handleing;      else if (angle < a && angle > -a)         angle += handleing;      x -= Math.sin(Math.toRadians(angle)) * speed;      y += Math.cos(Math.toRadians(angle)) * speed;`

lots of sillystupid games: http://www.emaggame.com
Pages: [1]
 ignore  |  Print

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

 numerical (56 views) 2017-02-21 07:32:16 numerical (55 views) 2017-02-21 07:31:46 theagentd (161 views) 2017-02-18 13:42:33 theagentd (164 views) 2017-02-18 13:35:16 h.pernpeintner (1327 views) 2017-01-24 22:39:11 h.pernpeintner (1315 views) 2017-01-24 22:38:32 Galdo (1875 views) 2017-01-12 13:44:09 Archive (1967 views) 2017-01-02 05:31:41 0AndrewShepherd0 (2506 views) 2016-12-16 03:58:39 0AndrewShepherd0 (2307 views) 2016-12-15 21:50:57
 SkyAphid 40x philfrei 27x theagentd 25x Archive 25x Spasi 22x princec 21x basil_ 21x misthalu 19x Coldstream24 16x Aalhex 15x wessles 14x orange451 14x dime26 11x Riven 10x SHC 9x KaiHH 9x
 List of Learning Resourcesby elect2016-09-09 09:47:55List of Learning Resourcesby elect2016-09-08 09:47:20List of Learning Resourcesby elect2016-09-08 09:46:51List of Learning Resourcesby elect2016-09-08 09:46:27List of Learning Resourcesby elect2016-09-08 09:45:41List of Learning Resourcesby elect2016-09-08 08:39:20List of Learning Resourcesby elect2016-09-08 08:38:19Rendering resourcesby Roquen2016-08-08 05:55: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