Game Development Community

Block rotation issue

by JJ62(#0005) · in Torque Game Engine · 03/01/2009 (5:21 am) · 2 replies

I working on maze game at the minute that involves the rotation of a block. I want to be able to press a button and make the block rotate around the Y axis by 90 degress each time. For example say I have a block that isn't rotated at all and is just at a 0 degree angle, I then press a button and its turned on its side equal to a 90 degree angle, I press a button again and its at 180, then 270 and so on. You can see that I want the block to keep rotating around the Y in circle. Here is my attempt at doing this in script.
function serverCmdRotateY(%client)
{
   //get current rotation and position stuff	
   %avatar=%client.player;
   %myTransform=%avatar.getTransform();
   %myPos=getWords(%myTransform,0,2);
   %myRot=getWords(%myTransform,3,5);
   %myRotTheta=getWord(%myTransform,6);

   //90 degrees in radians roughly
   %val=(3.14/2);

   //add 90 degress to current theta
   %theta=vectorAdd(%myRotTheta,%val);

   //make rotation around Y
   %rotY = "0 1 0 " SPC %theta;

  //add this rotY to current rotation value
   %angle=vectorAdd(%myRot,%rotY);

  //rotate at current position
   %g=matrixMultiply(%myPos,$angle) ;

   %avatar.setTransform(%g);
}
This code compiles but it doesn't work properly. The block seems to rotate from 0 to 90 and then back to 0 again, instead becoming 180, 270 and then 360. So it constantly goes from 0 - 90 - 0 - 90 instead of just goind round in a circle. Any help would be very much appreciated!

#1
03/01/2009 (1:16 pm)
at first glance I can see
//add this rotY to current rotation value
   %angle=vectorAdd(%myRot,%rotY);

  //rotate at current position
   %g=matrixMultiply(%myPos,$angle) ;
Should this be?:
//add this rotY to current rotation value
   %angle=vectorAdd(%myRot,%rotY);

  //rotate at current position
   %g=matrixMultiply(%myPos,%angle) ;//Note the % change here
#2
03/02/2009 (5:46 am)
Please ignore the fact that I have $angle instead of %angle this is just a typo. I did in fact have %angle in the code!!
So any suggestions? As I said above any help would be greatly apprciated as geting this correct is very important!!!!!!!