1

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!

4
  • Are you going for straight or curved paths? Using gravity?
    – jtbandes
    Aug 29, 2009 at 4:29
  • Sorry, should have explained better! I want a curved path with gravity, basically representing the real world action of throwing an object to someone.
    – ben
    Aug 29, 2009 at 5:29
  • I see this is tagged as iPhone. Be aware that NSBezierPath is only on the Mac right now.
    – Brad Larson
    Aug 29, 2009 at 14:48
  • Ah, thanks for the heads up. Anyone have any ideas as to how to do it without NSBezierPath?
    – ben
    Aug 30, 2009 at 1:13

1 Answer 1

0

I 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.