Burrito411
Burrito411

Reputation: 431

SpriteKit - SKSpriteNode physicsBody not forming to CGPath

I have an SKSpriteNode that looks like a trapezoid, with the code like this:

bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint:CGPointMake(0, 0)];
[bezierPath addLineToPoint:CGPointMake(90, 90)];
[bezierPath addLineToPoint:CGPointMake(374, 90)];
[bezierPath addLineToPoint:CGPointMake(462, 0)];

CGPathRef path2 = bezierPath.CGPath;
self.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path2];
self.physicsBody.dynamic = NO;

I remember reading somewhere that an SKSpriteNode must be convex, and this shape certainly seems convex. What happens in the program is, when a vehicle runs over this trapezoid shaped bump, what seems to happen is that the vehicle goes below the trapezoid shape. Can anyone help me with this problem?

Upvotes: 3

Views: 862

Answers (1)

Graham Perks
Graham Perks

Reputation: 23408

That's clockwise winding; it needs to be counterclockwise. Reverse the order of your points.

Upvotes: 5

Related Questions