PDA

View Full Version : Object Motion Question


Hoosier_Daddy
08-09-2003, 09:41 AM
Please open and examine the "apollo" swi provided by swishzone on their examples page. In it you will see an apollo sprite. I am trying to get my head around the motion logic. I wish to change it so that the motion is smoother. Currently it is set to rotate the object 45 degrees onpress of left or right. I would like to change it to maybe 10 degrees or so, but in doing so this messes up the other logic and I am unable to figure it out.

One of you script gurus mind looking at it for me?

Thanks,

~Jer~

dammitjanet
08-09-2003, 11:14 AM
thats a tough one, honestly? if you wanted to do this, then Id have to think about adding in actual physics equations for movement.

   if (Apollo.rot == 0) {
       Apollo.velX += 0;
       Apollo.velY -= Apollo.throtleSpeed;
   } else {
       if (Apollo.rot == 1) {
           Apollo.velX += Apollo.throtleSpeed;
           Apollo.velY -= Apollo.throtleSpeed;
       } else {
           if (Apollo.rot == 2) {
               Apollo.velX += Apollo.throtleSpeed;
               Apollo.velY += 0;
           } else {
               if (Apollo.rot == 3) {
                   Apollo.velX += Apollo.throtleSpeed;
                   Apollo.velY += Apollo.throtleSpeed;
               } else {
                   if (Apollo.rot == 4) {
                       Apollo.velX += 0;
                       Apollo.velY += Apollo.throtleSpeed;
                   } else {
                       if (Apollo.rot == 5) {
                           Apollo.velX -= Apollo.throtleSpeed;
                           Apollo.velY += Apollo.throtleSpeed;
                       } else {
                           if (Apollo.rot == 6) {
                               Apollo.velX -= Apollo.throtleSpeed;
                               Apollo.velY += 0;
                           } else {
                               if (Apollo.rot == 7) {
                                   Apollo.velX -= Apollo.throtleSpeed;
                                   Apollo.velY -= Apollo.throtleSpeed;
                               }
                           }
                       }
                   }
               }
           }
       }
   }

#the above is basically a load of nested IF's (a good case for a Switch Case structure huh?... . case for CASE? o never mind a bad pun anyway) that sets the delta change in X and Y to a proportion of the throttle speed (the proportion is pretty skewed here its either all or nothing)

the section after that is bounds checking on the rotation position and positioning variables.

any way, you will need to work out a proportional way of assigning the thrust vector (throttel speed) between the X and Y velocity vectors.

Since in the whole circle, it has 8 areas, each of 45 degrees, and the rotation the vessel would be less than the 45 degrees, then sicne you know the angle, you can work out the X and Y vectors proportions by using just SIN and COS

If we imagine that the thrust vector is a unit vector, then the Y proportion of the thrust vector will be given by the sin of the angle, and the X proportion of the vector will be given by the cosine of the angle.

(this is just tested for the first 45 degrees and will change for any negative values) assuming the variabel angle now contians the angle of the rocket.

Apollo.velX += Apollo.throtleSpeed*cosdeg(angle);
Apollo.velY -= Apollo.throtleSpeed*sindeg(angle);

dammitjanet
08-10-2003, 07:41 PM
Ok jer - ive edited the Apollo.swi to give the ability for a full 360 rotation - a bit of trial and error gets a playable game at about 15 degrees per keypress.

apart from a few minor changes eleswhere (the rotation amount on keypress and the bounds checkin on the rotation value) its as I posted above.

Hoosier_Daddy
08-10-2003, 08:19 PM
It doesnt seem to have the correct motion now. It does rotate as you said, but the up and down arrows dont seem to speed or slow correctly once rotated.

~Jer~

dammitjanet
08-10-2003, 08:23 PM
seesm to work ok for me, tho the speed may have changed slightly

multiplying the velX and vel y by 1.414 (inverse of sin(45)) might increase the responsiveness.

Hoosier_Daddy
08-10-2003, 08:30 PM
Actually after posting I went back and looked at the original and it also doesnt slow the momentum on push of up it merely reduces the current speed, but gravity keeps mementum intact so, your version works as I requested. Thanks again Stu I will compare the two files now.

~Jer~