I have a stick, that on touch become higher and after touch ended, rotates on 90 degress with duration. So i'm decided not to use for this joint pin and all make without physics, but i can not successfully add my stick to platform so, that it will rotates on 90 degress and pinned to platform from other side, so what i need is on picture:
My code is there, i'm making platform anchor, stick...
self.p_currentPlatform = [SKShapeNode shapeNodeWithRect:CGRectMake(-100/2, -320/2, 100, 320)];
self.p_currentPlatform.position = CGPointMake(50, 160);
self.p_currentPlatform.strokeColor = [SKColor grayColor];
self.p_currentPlatform.fillColor = [SKColor yellowColor];
self.p_currentPlatform.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_p_currentPlatform.frame.size];
self.p_currentPlatform.physicsBody.dynamic = NO;
[self addChild:self.p_currentPlatform atWorldLayer:VZWorldLayerCharacter];
self.anchor = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(1, 1)];
CGPoint pos = CGPointMake(_p_currentPlatform.frame.origin.x + _p_currentPlatform.frame.size.width,
_p_currentPlatform.frame.size.height);
self.anchor.position = pos;
self.anchor.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:.1f];
self.anchor.physicsBody.dynamic = NO;
[self addChild:self.anchor atWorldLayer:VZWorldLayerCharacter];
self.p_stick = [SKSpriteNode spriteNodeWithColor:[SKColor purpleColor] size:CGSizeMake(3, 50)];
self.p_stick.position = CGPointMake(_anchor.position.x, _anchor.position.y + _p_stick.frame.size.height/2);
self.p_stick.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:
CGSizeMake(_p_stick.frame.size.width, _p_stick.frame.size.height)];
self.p_stick.physicsBody.dynamic = NO;
self.p_stick.anchorPoint = CGPointMake(0, 0.5);
[self addChild:self.p_stick atWorldLayer:VZWorldLayerCharacter];
then on touch i make game state and in update method is going:
SKAction *resize = [SKAction resizeByWidth:0 height:kVZStickHeight duration:timeSinceLast];
SKAction *move = [SKAction moveByX:0 y:kVZStickMove duration:timeSinceLast];
SKAction *group = [SKAction group:@[resize, move]];
[self.p_stick runAction:group];
and after that i'm making rotation, but by "y" it's always going higher.
#define SK_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f)
CGPoint locationConv = [self convertPoint:location toNode:self.anchor]];
[self.p_stick runAction:[SKAction rotateByAngle:(atan2f(locationConv.y, SK_DEGREES_TO_RADIANS(-90)/*locationConv.x*/)) duration:1.0f]];
How to pin stick to platform like joint pin effect ?
First of all set anchor point:
Also you can set dynamic property NO for all.
You need to use this atan2f function