Find Jobs
Hire Freelancers

Cocos2d Collision Bug

$10-30 USD

Cancelled
Posted about 10 years ago

$10-30 USD

Paid on delivery
After continuously debugging and trying to fix this problem I am still have absolutely no luck…Can anyone please help me with this? It’s driving me insane.. I am using cocos2d v2 for iOS and basically I made a simple collision detection check method: -(bool)collisionWithPoint:(CGPoint)center1 andRadius:(float)radius1 andPoint:(CGPoint)center2 andRadius:(float)radius2 { float a = center2.x - center1.x; float b = center2.y - center1.y; float c = radius1 + radius2; float distanceSquared = (a * a) + (b * b); if (distanceSquared < (c * c)) { return YES; } else { return NO; } } I also have an array keeping track of my enemies being added to the scene. I alloc in the init method: _enemyFish = [[NSMutableArray alloc]init]; Then I add my enemy to the array like this: [self addChild:yellowFish z:50]; [_enemyFish addObject:yellowFish]; I also remove it from the array like this: CCMoveTo *move = [CCMoveTo actionWithDuration:speed position:ccp([login to view URL], randY)]; CCCallBlockN *done = [CCCallBlockN actionWithBlock:^(CCNode *node){ [_enemyFish removeObject:node]; [node removeFromParentAndCleanup:YES];}]; [blueFish runAction:[CCSequence actions:move,done, nil]]; Then in my update method I check for collisions: -(void)update:(ccTime)dt { for (CCSprite *enemy in _enemyFish) { if ([self collisionWithPoint:[login to view URL] andRadius:[login to view URL] * .3 andPoint:[login to view URL] andRadius:[login to view URL] * .4]) { [self gameOver]; } } } However, my issue is that my player will randomly die (gameOver scene being called) without being anywhere near the enemy. This only happens randomly though which confuses me. I have debugged with multiple CCLog statements to determine that this is indeed the issue. Does anyone have any idea why I would randomly be “colliding” with nothing based off of my given code? I can provide other code if needed. Thank you!
Project ID: 5754482

About the project

Remote project
Active 10 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs

About the client

Flag of UNITED STATES
Lakewood, United States
5.0
11
Payment method verified
Member since Aug 25, 2013

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.