SKPhysicsJoint allows orbit around a fixed point

Using spritekit physics syringes, how could you make an object orbit another at a fixed distance?

Object-A must not move Object-B, it must orbits Object-A when force is applied to it

To achieve this, I tried to set the SKPhysicsJointLimit constraint between two physical bodies, and then apply force to object-B. I find a behavior that is odd, but it may not be so ... What are the results of Object-B trembling but lasting forever and doesn't seem to be limited to Object-A, which doesn't move at all,

+4
source share
1 answer

If you look at the question , you will see that this is the opposite of what you are asking.

SKSpriteNode * ObjectA = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size: CGSizeMake(5,5)];
ObjectA.position = CGPointMake(size.width/2,size.height/2);
ObjectA.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:ObjectA.size];
ObjectA.physicsBody.affectedByGravity = NO;
ObjectA.physicsBody.dynamic = NO;


SKSpriteNode * ObjectB = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size: CGSizeMake(5,5)];
ObjectB.position = CGPointMake(size.width/2,size.height/4);
ObjectB.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:ObjectB.size];
ObjectB.physicsBody.affectedByGravity = YES;
ObjectB.physicsBody.dynamic = YES;


SKPhysicsJointPin *centerPin = [SKPhysicsJointPin jointWithBodyA: ObjectA.physicsBody bodyB: ObjectB.physicsBody anchor: ObjectA.position];


[self addChild: ObjectA];
[self addChild: ObjectB];
[self.scene.physicsWorld addJoint:centerPin];

This article helped a lot in sizing.

Hope this helps.

0
source

Source: https://habr.com/ru/post/1526318/


All Articles