Hi guys,
I need a little math help again. I'm trying to spawn some pickups along an arc that will follow roughly the players path when he jumps between 2 objects. I'm using box2D for the physics.
Here's the code I am using now. dir starts in the direction the pickups will begin spawning.
int maxCount = 10;
int count = 0;
bool continueSpawning = YES;
float a = TIMESTEP * GRAVITY;
while (continueSpawning)
{
Pickup *pickup = [Pickup spriteWithBox2dBody:self atPosition:spawnPos];
[self addChild:pickup];
dir = ccp(dir.x + a * PICKUP_SPACING, dir.y + a * PICKUP_SPACING);
dirNorm = ccpNormalize(dir);
spawnPos = ccp(spawnPos.x + PICKUP_SPACING * dirNorm.x, spawnPos.y + PICKUP_SPACING * dirNorm.y);
count++;
float endObjectSize = [endObject scaledSize].width / 2;
if(ccpDistance(spawnPos, endObject.position) < PICKUP_PADDING + endObjectSize / 2|| count >= maxCount)
continueSpawning = NO;
}
I don't know if my math is close or not. I'm going off some stuff I found in other forums. But it seems to give me good results as long as the endObject is at the same height or below the beginning object. If its at a higher hight (the end object can be quite a bit higher) then the pickups seem to spawn almost in a straight line with barley any arc.
What can I do to fix this? I'm sure my math is not right ;/
Thanks again!