Hello! I am making an isometric game on the iPhone, and need a little help. What is the best way to go about calculating the path a object must take if it is thrown from one tile to another? I've been looking into using NSBezierPaths, but can't quite work out how to use them for the objects path? Any help would be greatly appreciated!
views:
264answers:
1I would advise not using vector graphics (NSBezierPath) for what you need to accomplish.
You could use a CGPoint to represent the position for each game object (assuming this is a 2D game). (Put this struct inside a GameObject class).
struct objectPhysics
{
CGPoint position;
CGPoint velocity;
}
Use speed and direction vectors to calculate the trajectory of the object. Assuming the following are vectors:
position = position * velocity * timeDifference;
When an event happens (such as the user clicking on an object or detecting a collision), set the velocity vector to a value (1, 0.5) or something which means move +1 in the X direction and 0.5 in the Y direction per frame (or unit of time if you have "* timeDifference").
You should take a look at this site for tips on beginning game programming and some of the vector math you will need in order to calculate the direction that you need to accelerate in.
The time difference is a measure of how much time has passed since the last frame is used to make sure that objects move the right distance to keep in sync with your frame rate.