Tag Info

New answers tagged

0

First, the behavior you're describing is that of an aerodynamic vehicle with a single vector of force. A spaceship, flying in space, would operate in an entirely different manner. If this is still the desired behavior: Second, to utilize SpriteKit's efficiency, it might be best to use actions on your nodes. This isn't a requirement, but they exist ...


0

I'm just learning SpriteKit myself, however I think the following would be faster: - (BOOL)checkCollisionForSpikePoint:(GCPoint)spikePoint ballCenter:(CGPoint)ballCenter ballRadius:(CGFloat)ballRadius { CGFloat hypotenuse = sqrt(exp(spikePoint.x-ballCenter.x,2) + exp(spikePoint.y-ballCenter.y,2)); ...


0

I think most of your problems might be solved by understanding the use of category masks. Simply set the masks to ignore contact and collision between the sword and player categories. Specifically, this is done by assigning unsigned integers to the categoryBitMask, collisionBitMask, and contactBitMask properties of the SKPhysicsBody of the SKSpriteNode in ...


0

Stacking Issue Regarding the stacking issue, I am not sure how your class is setup, but I would consider handling the positioning of the stacked elements based on an indexed approach. For Instance (pseudo code): class Skewer : MonoBehaviour { public List<SkewerElements> skewerElements = new List<SkewerElements>(); public float ...


0

The simplest means of determining if there is contact after your touches finish is to alter the category of the "ball" to a category that registers contacts with the "bucket". That is to say, your ball would have a category that ignores the bucket until the ball is dragged and the touches end (touchesEnd method), at which point the category of the ...


1

Remember that SpriteKit's physics system is based on "SKPhysicsBody"s, which are added to "SKSpriteNode"s. Those physics bodies, however, needn't be attached to visible nodes. The simplest method is to create a SpriteNode with no actual sprite or visible body, add it as a child to the area you want on the visible shape, and categorize it differently from ...


0

Really, a for loop is usually better for iteration. Taking @noel 's answer: b2AABB aabb; aabb.lowerBound = b2Vec2(FLT_MAX,FLT_MAX); aabb.upperBound = b2Vec2(-FLT_MAX,-FLT_MAX); for (b2Fixture* fixture = body->GetFixtureList(); fixture; fixture = fixture->GetNext()) { aabb.Combine(aabb, fixture->GetAABB()); } The expression fixture, taken as ...


1

Typically a physics engine will follow these steps: Broad-phase collision detection. Typically using bounding volumes, this reduces the set of all objects to a small subset of potentially colliding objects. Some data structures to handle broad-phase are AABB trees, KD-trees, Octrees, etc. Narrow-phase collision detection. From the subset of potential ...


0

The simplest possible solution would be to maintain the horizontal velocity, and flip the sign of the vertical velocity, after multiplying it by an elasticity factor. vec2 velocity; vec2 position; position += velocity * dt; if (collision) { position = adjust_position(); // to not collide anymore velocity.y = -velocity.y * elasticity; } If you're ...


2

Ok, think I got an answer for you. The short version: compute the friction force F = friction * velocity before you start the loop and apply it in do Physics() like this: v -= F * deltaTime. Long version: the assumption you're making that it should work independent of frame time only works with constant acceleration, like the one you're applying in ...



Top 50 recent answers are included