Java-Gaming.org Hi !
 Featured games (88) games approved by the League of Dukes Games in Showcase (681) Games in Android Showcase (196) games submitted by our members Games in WIP (745) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Slope Help!  (Read 918 times) 0 Members and 1 Guest are viewing this topic.
Shin_Bet

Senior Newbie

 « Posted 2006-01-19 00:46:39 »

Hi, im making a game and i need some help in calculating some slope stuff.

i basically have two points, and i want to draw a ball travelling between the two. I used Y = mX + b...But when the X points start becoming similar this method goes to pot. It also has differnet speeds depending on where you shoot. Any help is appreciated, thanks.
noblemaster

« JGO Spiffy Duke »

Medals: 32
Projects: 11

Age of Conquest makes your day!

 « Reply #1 - Posted 2006-01-19 01:26:56 »

Your question is not so clear, but let me give it a try!

Let's assume your 2 points are given as (x0, y0) and (x1, y1).
The x and y distances are given as:
dx = x1 - x0;
dy = y1 - y0;

The total distance is (Pytagoras):
d = Math.sqrt(dx * dx + dy * dy);

So, to move with constant speed from (x0, y0) to (x1, y1) you have to
define a speed, e.g.
speed = 5;

Let's assume your current position is given as x and y. For each time step, you apply
the following transform:
x = x + dx * speed / d;
y = y + dy * speed / d;

Pages: [1]
 ignore  |  Print

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

 CopyableCougar4 (61 views) 2016-06-25 16:56:52 Hydroque (93 views) 2016-06-22 02:17:53 SwampChicken (96 views) 2016-06-20 13:22:57 SwampChicken (99 views) 2016-06-20 13:22:49 SwampChicken (91 views) 2016-06-20 13:22:26 Hydroque (136 views) 2016-06-15 08:22:50 Hydroque (131 views) 2016-06-13 06:40:55 DarkCart (245 views) 2016-05-29 02:30:33 Hydroque (212 views) 2016-05-26 14:45:46 Mac70 (196 views) 2016-05-24 21:16:33
 Spasi 49x theagentd 43x NegativeZero 39x KaiHH 29x LiquidNitrogen 23x princec 21x DavidBVal 17x CoDi^R 16x ra4king 13x ags1 10x Opiop 10x TritonDreyja 10x Archive 9x purenickery 9x Hydroque 8x czak 7x
 Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17
 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