Sprite Kit Multiple Collisions -
i'm going through tutorial/class making game in sprite kit , i'm having issues multiple collisions happening @ same time.
i'm implementing didbegincontact: method collisions make ball bounce because there seems known issue objects may "stick" body if velocity low , angle narrow.
by making _ball.physicsbody.collisionbitmask = 0;
and putting below line in didbegincontact
if(other body == firstbody && _ball == secondbody) secondbody.velocity = (cgvectormake(secondbody.velocity.dx * -1.0, secondbody.velocity.dy));
(or dy * -1.0 vertical collisions)
i can make object bounce naturally , works.
the issue i'm having when there multiple contacts called on _ball. if 1 collision makes _ball reverse direction , hits object of same type reverses direction again, _ball continue moving in it's original direction (double negative). _ball moves through these objects. can make bounce if secondbody.categorybitmask = 0; have issue of returning _ball it's original category.
does know if cycle through contacts or stop contacts on body after processes contact once?
any thoughts?
i had many problems correct amount of collisions. one, none. tried , works. thing change in didbegincontact method.
i presume declared categories correctly implemented physics delegate. so:
//define collision categories on top of implementation file static const uint32_t category1 = 0x1 << 0; static const uint32_t category2 = 0x1 << 1; static const uint32_t category3 = 0x1 << 2;
try replace code in didbegincontact one. remember correct collisions got work after did this.
-(void)didbegincontact:(skphysicscontact *)contact { sknode *newfirstbody = contact.bodya.node; sknode *newsecondbody = contact.bodyb.node; uint32_t collision = newfirstbody.physicsbody.categorybitmask | newsecondbody.physicsbody.categorybitmask; if (collision == (category1 | category2)) { nslog(@"hit"); } }
hope helps
Comments
Post a Comment