1

How to apply a impulse that make ball fly given distance in Cocos2d?

anonimek
  • 11
  • 1
  • depends on the mass of the ball, if you want to ignore mass set velocity directly instead of applyImpulse – CodeSmile Jul 22 '14 at 11:34
  • _physicsNode.space.gravity is ccp(0,-100); _ball.physicsBody.mass = 1.0f; I want to shoot my ball 800 pixels up. What power i should use. – anonimek Jul 22 '14 at 11:51
  • impulse is multiplied by inverse of mass (1.0/mass), ie assuming velocity is 0 then: velocity = impulse * (1.0 / 1.0) or in other words: velocity = impulse in this case ... but then integrating gravity over time in this equation is beyond me. If you used impulse of y=900 the ball would be 800 pixels up in the next frame. Impulse 500: 400 + 300 = 700 in two frames but too far in the third frame. – CodeSmile Jul 22 '14 at 14:34
  • How fast do you want to get it there? There's more to the physics of it than just force. – PWiggin Jul 23 '14 at 00:56
  • I want time to by const no matter to distance. – anonimek Jul 23 '14 at 06:38
  • Then you want to make a velocity variable that is inversely proportional to the distance traveled. – PWiggin Jul 24 '14 at 03:13
  • Can you guys please check my question: http://stackoverflow.com/questions/31898824/how-velocity-impacts-on-ccsprite-in-cocos2d-chipmunk and suggest me how distance, time, height, angle, etc. are being calculated by setting velocity only..? in Chipmunk? Because as seen in console in question I use same velocity but distances travelled are different. I want distance travelled same, so, need to apply precise velocity factor. – Paresh Thakor Aug 09 '15 at 11:42

0 Answers0