HelloLoop/Update issue with Scaling and Translation first few loops

nevermind, I suck -_^ … posting the question here made me look at it differently somehow and I spotted the errors, and they were mine :wink:
Writer’s note!!
Writer’s note!! – This could possibly be a better written post but my head’s spinning right now, corrections may show up when I get some focus back…
Writer’s note!!

Read the writer’s note.

Hey, I’m on the HelloUpdate or HelloLoop tutorial (4), doing the excercises

3. Can you make a cube that pulsates? (grows and shrinks)
5. Can you make a rolling cube? (rotate around the x axis, and translate along the z axis)
- note: I made rolling cube rotate around z and translate around x for left-right movement rather than forward/backward … it added up with 3 other boxes to make a… funky face… so to speak… :smiley:

While I did manage to fix the issue with a little hustling / adjusting for the seemingly erroneous behaviour, it still bothers me and it might turn into a bigger issue along the road…

I run the .java file
the monkey launcher shows up
I start the damn thing
my cubes show up as they should

the cube that I have rolling left and right does so
it rolls from center to the left, then right and back left
BUT on the first pass to the left from center, it rolls more than it should, messing up the left-right ping-pong rolling which starts after the firstleftroll …
ALSO the cube I made grow, on it’s first growth spurt before I reset it’s scale, scales up way bigger than it does the other times/loops/updates

in a nutshell: left-right roll moves too far left on first roll ; and ; scaleup scales up too much on the first scale up
- again, after first honkey-dory (…) everything acts as intended, but first time round it’s overdoing it - resulting in … badness… :wink:

Anyone know what might be going wrong?..
I can post pics of code but getting a vid going to show my edited tutorial at work is… beyond me…

I’ll show some of the code I used here in case it might be helpful…:

The roll code :

mio2 += tpf; 

        if (mio2 < 1.0f && firstleftroll == true) {
        player4.move(-1.0f*tpf, 0.0f, 0.0f);
        // roll left from center 1 sec

        else if (mio2 < 1.0f) {
            player4.move(-1.0f*tpf, 0.0f, 0.0f);
            // roll left from sec0 to sec1

        else if (mio2 >= 1.0f && mio2 < 2.0f) {
            player4.move(1.0f*tpf, 0.0f, 0.0f);
            // roll right from sec1 to sec3
            firstleftroll = false;

        else if (mio2 >= 2.0f) {
                mio2 = 0.0f;

end rollcode

edit: I actually may have just fixed this by changing the speed on first roll so it goes 50% of a whole movement left, then whole right, then left and loops fine… not sure if it still got pushed a bit too far but it looks right.
regardless, the growing cube still grows too much during the first round…

code for growing and resetting the cube's size – ok actually also has code that changes the material for that excercise… :

mioCounter += tpf;
        if (mioCounter <= 2.0f) {
        player2.scale(1 + 0.7f*tpf);

         if (mioCounter >= 0.70f && mioCounter <= 1.3f){
         else if (mioCounter >1.3f) {
        else {

        mioCounter = 0.0f;

end of scaling code

edit again: ok the difference in the scaling might be the initial cube which scales, starts at scale(1), but I then push it down to 0.5 and expect the scale-up from 1 to result in the same as the scale -up from 0.5… which… is … wrong… of me…

Thanks …

scale() is multiplicative, the algorithm you are using is going to vary the scale based on frame rate.

Instead accumulate a float scale and add 0.7f*tpf to it each frame then do a setLocalScale(accumulatedScale).

zarch - managed to fix it with my low lvl magical sorcery - but thanks =)


No worries. But do keep in mind that multiplication works differently from addition - you can accumulate translations (your movements) fine but you can’t accumulate multiplications the same way and remain frame-rate-independent.