Cocos2d Chipmunk gravity and collision detection - iphone

I have a simple animation in Cocos2d Chipmunk with the tasks:
One round shaped sprite situated in the center of the screen, rigid body type. Center of gravity needs to be located in center of this sprite.
From different sides of screen (spontaneously and beyond screen size) other rigid round sprites must fall into central sprite to fill visible screen space.
Sprites should not overlap one another.
So the questions are:
How to reassign the vector of gravity to the center of the screen?
How to implement collision detection between rigid body types in Cocos2d Chipmunk?
Thanks, colleagues!

You can't set a center for the gravity. You can only set a direction (the same for all objects). It's possible to create an effect you describe, but you'll have to do the work yourself. In every frame you have to set a force or apply an impulse on every body in the direction of your gravity. And the "regular" chipmunk gravity should be (0, 0).
See this tutorial about collision detection.

Related

Two Colliders overlap a little bit each other in Unity

After coding left and right movement of player which had BoxCollider and Rigidbody, An serious problem happened. when player moved toward an cube which had BoxCollider, player's collider overlapped with the cube by 0.02. Please tell me how to fix this problem.
For your information, the movement that I made was by rigidbody.MovePosition in FixedUpdate. And I already set collision detection to continuous. Also, I set the friction to zero with Physics Material.
When player don't move, the x Position is 2.525 enter image description here
But when player move, the x Position is 2.545 enter image description here
Colliders overlap - it's how collision detection works. If the overlap is too great, you can make one or both of them bigger, make the physics settings tighter, or some combination of these. Note that the amount of overlap is also affected by the speed of the objects - the more speed, the more potential overlap. What you can't do is expect PhysX to work with no collider overlap.

unity slide sphere on a slope without rotating

I have a ramp and I move a sphere with arrows. I have unity's gravity and I want the rigid body of sphere to slide when it is stoped at the top of the ramp but without rotating it's body. The problem is if I Freeze rotation on x axis, it won't slide.
Try to use physics materials like ice and freeze rotations.
See info about materials here. "Like ice" means than you need set frictions to zero.
You should create a new Physical Material and set both dynamic and static friction to 0. Then drag it to the sphere and maybe also to the ramp.
Test with both rotation constrained and not.

How to rotate a SKPhysicsBody in SpriteKit with Swift

I am trying to make a brick breaking game with SpriteKit in Swift. To make the paddle I am trying to make it so that there are two SKPhysicBody, one for each half. To control the angle of which the ball bounces off the paddle, I want to rotate the physics body. I tried to use applyAngularImpulse or just applyForce, but they did not work. Is there a way to rotate the physics body??
You can't set the rotation of a physics body. You can however set the rotation of the node that the physics body is attached to. So what you can do is make a dedicated node for your physics body. This node will be invisible, it will only exist for you to rotate.

Check for absence of contact

I'm developing a puzzle platform game using Sprite Kit (and its physics engine). My player's physics body consists of a large hitbox covering most of the sprite, and a wheel with a pin joint anchored at the bottom of the hitbox. Rotation is added to the wheel to make the player move across the screen.
I need to know if the player is on the ground, or has fallen off a ledge; I know how to check for a physics body contact, but is it possible to check for an absence of contact (i.e. when the wheel leaves the ground)? I can't rely on comparing the Y position from the last frame as there are sloped surfaces that the player climbs.
You can use the didEndContact:(SKPhysicsContact *)contact to check if the wheel is no longer contacting the ground. Same principal as the didBeginContact:(SKPhysicsContact *)contact just in reverse.

To follow a ball character like monkey kick off game

I am working on a game which has working similar to game monkey kick off. I have one ball bouncing on a place at the left side of screen and depending upon the position of the ball I apply linearImpulse to the ball on user touch so that it appears that the ball is kicked.
But what happens is when i apply impulse the ball goes out of the screen bounds. I dont want the ball to go out of the horizontal screen bounds whereas it can go out of the screen vertically.I tried using CCFollow but it doesn't give the realistic feel to the game flow.
I tried THIS tutorial, but dint help much.I managed to scroll the background,Only this part remains.
Any Ideas on how the ball should not move out of the horizontal screen boundary..? but in case of vertical boundary on the other hand it can go out of the bounds.
If you're not using physics, it's a simple bounds check. Assuming the screen width is 320 points this will keep the ball inside the screen horizontally:
CGPoint ballPos = ball.position;
ball.position.x = fmaxf(0, fminf(320, ballPos.x));
ball.position = ballPos;
UPDATE: I noticed you mentioned linear impulse. So you're using a physics engine. In that case, create a horizontal wall on both sides. See the cocos2d Box2D or Chipmunk templates how to enclose the screen with a collision border, then use only the left and right side borders in your game.