To follow a ball character like monkey kick off game - iphone

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.

Related

Detect When SKPhysicsBodies Overlap

I have two SKSpriteNodes, one is a thin vertical rectangle dividing the screen and the other is a ball bouncing from side to side. When the ball touches the divider a contact is triggered as expected. However, while the ball is moving through the divider I would like to continue to trigger the contact function for each frame.
How can I detect when two SKPhysicsBody objects overlap? I had some success using the intersectsNode() function but that uses the sprite's image size, which doesn't always match the physics body outline so I'm looking for an alternative.
Thanks!
See the allContactedBodies method in the docs.

How do I make my character's arms point towards the camera or cursor in Unity?

I'm making a fps game and I want my character's arms to rotate up and down depending where the cursor/camera is pointing at. The character already rotates when I turn left or right. Hopefully someone can answer my question. I'm new to Unity and I'm still learning how to code in C#.
For top and bottom rotation, create an animation for top aim, eye level aim and feet aim. send the value of your rotation to animator controller and animate according to it.

Cocos2d Chipmunk gravity and collision detection

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.

mouse joint is not working to restrict the ball in the half part of the screen

Hi guys I Am developing the application in cocoas2d using the box 2d frame work but unfortunately
i'm not able to restrict the gray ball in the half screen area of the image shown here
i want that ball not to go opposite part of the screen
I Have Used The b2Mousejoint For to move the ball around the screen
b2PrismaticJointDef restrict on any particular axis
But
i want to restrict on the particular rect area of the screen
You could create your custom distance joint which will restrict global axes of the ball. But it will be hard if you never write your own physics engine.
There are 2 easier ways to implement what you want.
Create 4 static "border" boxes around the area where the ball must stay. Then place the ball and the boxes into one collision group.
However, the response of the "border" boxes will not be instant. Therefore, the ball at high speed will sometimes "sink" into the boxes, then be popped out.
You can correct the position and reset the speed of the ball manually in code when it crosses the bounds of the desired area. But it may lead to the unstable physics simulation.

Problem regarding CCFollow and CCParallaxNode

I have a problem regarding CCFollow. I am using CCFollow along with CCParallaxNode. I have added layers to parallax node and then apply runaction: on parallax node.
[pn runaction:[CCFollow actionWithTarget:sprite worldBoundary:CGRectMake(0, 0, 5600, 320)]];
but using this the sprite always runs at middle of screen. Is there any way to keep it at left of screen and also layers follow this sprite?
Thanx.
If you want your player to remain on the left side of the screen, then lock the players X position to a specific region that makes sense. You should also be moving the background and other elements of your game, not your player (with exceptions, to the players position visually on the screen).