I'm still super noob in spritekit and trying to get some tutorials here and there..
I'm trying to have stickman figure like this To jump of a high building and bounce when hit the ground node
It works fine when the node is ball with physicsbody of circle
But when trying physics body of rectangle .. it never bounce.. I've even tried this snipt of code
SKSpriteNode * victim = [SKSpriteNode spriteNodeWithImageNamed:@"victim_base"];
victim.position = CGPointMake(5, 500);
victim.zPosition = 2;
victim.name = @"victim";
victim.xScale=0.7;
victim.yScale=0.7;
[self addChild:victim];
CGFloat offsetX = victim.frame.size.width * victim.anchorPoint.x;
CGFloat offsetY = victim.frame.size.height * victim.anchorPoint.y;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 13 - offsetX, 59 - offsetY);
CGPathAddLineToPoint(path, NULL, 43 - offsetX, 58 - offsetY);
CGPathAddLineToPoint(path, NULL, 38 - offsetX, 3 - offsetY);
CGPathAddLineToPoint(path, NULL, 7 - offsetX, 3 - offsetY);
CGPathCloseSubpath(path);
victim.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];
victim.physicsBody.friction = 0.0f;
// 4
victim.physicsBody.restitution = 1.0f;
// 5
victim.physicsBody.linearDamping = 0.0f;
// 6
victim.physicsBody.allowsRotation = NO;
[victim.physicsBody applyImpulse:CGVectorMake(10.0f, -10.0f)];
And setup of the gravity world is
self.physicsWorld.gravity = CGVectorMake(0.0f, 0.0f);
// 1 Create an physics body that borders the screen
SKPhysicsBody* borderBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
// 2 Set physicsBody of scene to borderBody
self.physicsBody = borderBody;
// 3 Set the friction of that physicsBody to 0
self.physicsBody.friction = 0.0f;
but he is jumping and just stay still on the ground with no bouncing
I really can't figure what is the wrong here.any help will be appreciated.
self.frame
value when setting theself.physicsBody
property. – Daniyar