Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 962
Burrito411 Avatar asked Nov 19 '25 05:11

Burrito411


1 Answers

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

like image 50
Graham Perks Avatar answered Nov 21 '25 17:11

Graham Perks