Comparing object positions

Hi,

What's the best way of comparing two object positions? I have characters and allowed starting positions which I load in an editor like this:

Code: Select all

    //Load Characters
    for (CharacterPosition *characterPosition in self.dataLevel.placedCharacterPositions) {
        ToolBarCharacter *character = [[ToolBarCharacter alloc] initWithData:characterPosition];
        [self addChild:character];
        [spritesOnScreen addObject:character];
        [dictionary setObject:character forKey:[NSString stringWithFormat:@"%@", characterPosition]];
    }
   
    //Load allowed character positions
    for (CharacterPosition *allowedPosition in [self.dataLevel allowedCharacterPositions]) {
        ToolBarStartPos *pos = [[ToolBarStartPos alloc] initWithData:allowedPosition];
        [self addChild:pos];
        [spritesOnScreen addObject:pos];
        [dictionary setObject:pos forKey:[NSString stringWithFormat:@"%@", pos]];
    }


I want the user to be unable to start the simulation if the placed character position is not within an allowed character position, and am therefore wondering if there is any way of comparing the two?

Thanks!
A common way might be to check the distance between two points:

Code: Select all

b2Vec2 posA, posB;
float distance = (posA - posB).Length();
irresistible force wrote:A common way might be to check the distance between two points:

Code: Select all

b2Vec2 posA, posB;
float distance = (posA - posB).Length();


I figured as much. At first I thought about using sensors, but that might a bit overkill.
In any case, thanks for the answer and sorry to be asking such a basic question.

Original thread: https://box2d.org/forum/viewtopic.php?t=9112