Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Slope Help!  (Read 450 times)
0 Members and 1 Guest are viewing this topic.
Offline Shin_Bet

JGO n00b
*

Posts: 14



« on: 2006-01-18 19: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.
Offline noblemaster

JGO Ninja
***

Posts: 730
Medals: 6


Age of Conquest makes your day!


« Reply #1 on: 2006-01-18 20: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]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.106 seconds with 20 queries.