Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>thoght your question not programmatical but physical (mechanical). </p> <p>position of object can be calculated from the system of equation:</p> <pre><code>x = Vx * t + x0 y = (-g*t*t)/2 + Vy * t + y0 </code></pre> <p>, where g - Gravitational acceleration, V - initial speed, Vx and Vy - its projections on axes X and Y, respectively.</p> <p>Question is what's the highest point, i.e. we need to found MAX(y(t)). derivative: <code>y'(t) = -g*t + Vy.</code> </p> <pre><code>y'(t) should equals zero, -g*t + Vy = 0; t = Vy/g; MAX(y) = y(Vy/g) = Vy*Vy/2g. MAX(y) = Vy*Vy/2g + y0 // ballistic trajectory MIN(y) = y0 - Vy*Vy/2g // your case </code></pre> <p>End you should calculate velocity accroding to this, if you want your bird Y to be in certain range.</p> <p>Addition:</p> <blockquote> <p>btw is there a sample cocos2d code for parabola?</p> </blockquote> <p>Here is my working code.</p> <pre><code> - (void) update: (ccTime)dt { t += dt*20; ... [self getVertices]; } - (void) getVertices { //for every index: { ... //getting initial position (x0, y0) ... vertices[index] = ccpAdd(vertices[index], ccpMult(velocity[index/3], t * screenFactor)); //+velocity*t vertices[index] = ccpAdd(vertices[index], ccpMult(gravity, (t*t/2) * screenFactor)); //+acceleration*t^2 /2 //} } </code></pre> <p>1) As you can see, there's no need to calculate Velocity every time: use initial speed. 2) Vertices is CGPoint array of current Sprite positions. 3) t (current time), vertices, gravity, velocity are instance variables of common class.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload