movement in 2D
Hi,
i would like to develop a program to make a playbook for american football. I haven't run across a free application that does this so i want to try it myself.
The view would be 2D and all players would have an x, y coordinate, velocity, acceleration and agility for starters.
You would plot out a course for a player by clicking on the field and thus creating a list of x,y points the player would have to run too.
But i'm not sure how i can calculate the next position given the player his current x,y coordinate and speed. Or if i count in the agility, how fast a player can turn. Are their any tutorials (java or c++) that show how to do this?
Thanks
Hello,
I have read your msgs. and i have a question to ask.
I am try to do a very basic thing it seems to me.
just an oval shape that moves to where the (x,y) point where i click.
I am using a JApplet Graphics object
the problem is...
the drawOval() method doesn't take as parameters but int data type.
round()*** the values generated from they way you mentioned earlier will only result in loss of precision and will end up with the ball moving to a totally different area.
do you have any ideas?
I ususally use something like this..
public class Vector2D {
double xmag,ymag,totalMag;
double angle; // in radians
public MotionVector(double xmag, double ymag){
this.xmag = xmag;
this.ymag = ymag;
// Arc Tangent of y over x yields angle
angle = Math.atan((double)(y/x));
// Pythagrean (spelling?) theorem
totalMag = Math.sqrt((double)((xmag*xmag)+(ymag*ymag)));
}
/*
* getters & setters
*/
}
And when I need to translate my object to draw I just get the x and y magnitudes in units per second, multiply them by the elapsed time since the last redraw ((Units / Seconds)*Elapsed Seconds = Units). If, for instance the player needs to change direction, just set the variables for its cooresponding Vector2D object and wait for the next redraw. If you want to add acceleration, just tack on another vector of which you multiply by the time squared to get its unit-change.
// Keep in mind that this is untested, but to my knowledge it should work given you create the addVectors(Vector2D []) method.
import java.awt.geom.*;
public class MotionObject{
Vector2D [] velocities;
Vector2D [] accelerations;
public MotionObject(Vector2D [] velocities, Vector2D [] accelerations){
this.velocities = velocities;
this.accelerations = accelerations;
}
public Point2D.Double getResultantMagnitudes(double time){
Vector2D vsum = addVectors(velocities);// you'll need to create this method, to add vectors together
Vector2D asum = addVectors(accelerations);
double deltax = (vsum.xmag * time) + (asum.xmag * (time*time));
double deltay = (vsum.ymag * time) + (asum.ymag * (time*time));
return new Point2D.Double(deltax,deltay);
}
}
To make use of an object like that, you would create your Vector2D arrays, then pop them into a new MotionVector object. And when it came time to find out where your player/object should be on screen, just call getResultantMagnitudes(double time) with the elapsed time and add the x and y values of the returned Point2D.Double instance to the current x and y locations of your onscreen object.
Hi, i was going to suggest spline curves, but a person does not move at a constant speed though the points.
After a way point the velocity would equal the last velocity - (change in direction) + agility.
or int v1 = v0 - (d0 - d1) + agility
depending on how you represent direction, and agility.
Have a look at http://www.gamedev.net/reference/
Harley.