How to make a free falling sprite node sit on another horizontally moving sprite body?
Now the both both bodies collide. But the horizontal moving body is deviated from its path and free falling body goes down after hitting horizontal body. How can fix this changing settings of the sprite nodes.
I have made given collision and category bit mask for collision to happen correctly.
freefalling body properties:
horizontal moving body properties
dynamic = YES affectedbyGravity = NO friction = 1.0
an oscillation action is performed on this body.
Adjusting the mass can help in not deflecting the moving object. For example try this code,
SKSpriteNode *fallNode = [[SKSpriteNode alloc] initWithColor:[UIColor redColor] size:CGSizeMake(25, 25)];
fallNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:fallNode.size];
fallNode.position = CGPointMake(100, 400);
fallNode.physicsBody.mass = 1;
fallNode.physicsBody.allowsRotation = NO;
fallNode.physicsBody.restitution = 0.0;
fallNode.physicsBody.friction = 1.0;
[self addChild : fallNode];
SKSpriteNode *moveNode = [[SKSpriteNode alloc] initWithColor:[UIColor greenColor] size:CGSizeMake(25, 25)];
moveNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:moveNode.size];
moveNode.position = CGPointMake(50, 100);
moveNode.physicsBody.mass = 100000;
moveNode.physicsBody.affectedByGravity = false;
moveNode.physicsBody.friction = 1.0;
moveNode.physicsBody.velocity = CGVectorMake(90, 0);
[self addChild : moveNode];