Hello,
I wonder if someone could give me a quick hand with the logic for an simple falling object that bounces inelastically, that is, it doesn't bounce back to the same height as before and will reach a point of rest. It's for a general 2D game object framework thingy that I fancied having a go at doing.
Anyway, here's what I've got so far:-
So far the object bounces once and then stops. When it collides with another object the velocity is inverted, like so:-Code:tt = me->pvData; // get our pointer to extra info for this type if (tt->dVelocity != 0) { // We're on the move if (fabs(tt->dVelocity) < 0.1) { // Below minimum clout, if there's something below stop if (DetectRect(me, me->x, me->y + 1, me->w, me->h)) tt->dVelocity = 0; } else { // Keep going tt->dVelocity += GRAVITY * 0.02; // 1/60 second me->y += (tt->dVelocity - (int)tt->dVelocity >= 0.5) ? (int)tt->dVelocity + 1 : (int)tt->dVelocity; } } else { // We're stopped. If there's nothing holding us up... if (!DetectRect(me, me->x, me->y + 1, me->w, me->h)) { tt->dVelocity += GRAVITY * 0.02; me->y += (tt->dVelocity - (int)tt->dVelocity >= 0.5) ? (int)tt->dVelocity + 1 : (int)tt->dVelocity; } }
Using dVelScale like that is probably not the best way to achieve what I want, but I want to use a simple model, people can adjust this value to give different effects.Code:tt->dVelocity = -tt->dVelocity * tt->dVelScale; tt->dVelScale += 0.1; // try to give a ping-pong ball effect (retains more energy the closer it is to rest)
Can anyone describe how I can best check if the object needs to start/stop moving?



LinkBack URL
About LinkBacks



CornedBee

