0

I am developing a jump game, in that when tapped on screen, I need to make the player jump up. So, I used following code.

[_player.physicsBody applyImpulse: ccp(0, player.physicsBody.mass * 155)];

in touchBegan method.

The code for CCSprite *_player is

_player = [CCSprite spriteWithImageNamed: @"Assets.atlas/Player.png"];
[_player setPosition: ccp(160.0f, 210.0f)];
_player.zOrder = 99;

_player.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, _player.contentSize} cornerRadius:0]; // 1
_player.physicsBody.collisionGroup = @"playerGroup"; // 2
_player.physicsBody.collisionType = @"player";
//[_physicsWorld addChild:_player];
[_foreground addChild: _player];

This code explains that the player is setup with physics body and added into some _foreground view. The issue is with applyImpulse method written in touchBegan. When it makes player to jump, the player jumps slowly, I want it to make somewhat faster, like, jumping hulk, start speedily and end slowly. How can we manage this without using animation? Because applyImpulse will not allow to use animation, I think.

Please help me on the topic, any suggestion, hint, anything that I can use?

Paresh Thakor
  • 1,795
  • 2
  • 27
  • 47
  • A simple, once-only impulse only works if you make the impulse, the mass of the object and the world gravity match up so that it "feels right". However this is typically too limiting. Depending on the game style you may need to work with setting the velocity directly on the first frame, perhaps even ensuring the upward velocity remains constant for a couple of frames. Perhaps even manually decelerating the object on top of gravity afterwards. There's no silver bullet, you just need to experiment with a variety of possible ways to make jumping "feel more realistic" (whatever that means). – CodeSmile Oct 28 '14 at 10:24
  • Thanks @LearnCocos2D. I try to experiment with the same you explained me. But as you might have seen the code, I calculate the impulse multiplying mass of the player, the issue is move feels very dull, I want to make it fast, a bit fast. Any properties or maths to make these moves fast..? – Paresh Thakor Oct 28 '14 at 11:41
  • any update for this? – Paresh Thakor Nov 07 '14 at 10:45

0 Answers0