Game Development Community

Scripting moving objects

by Lucus · in Technical Issues · 05/10/2008 (8:28 pm) · 5 replies

Hello,

How can I create multiple instances of the same shape with different variables. When i create more than one instance the values are getting added together.


Example:

the object moves side to side

------------> goes right then goes left
<-----------

the problem is when I add more than one shape of the same datatype the objects x values get combined.
The objects still move side to side like above, but go racing down the x axis further with each pass.

second door

------------>
<-----------

both slowly start going --------------------------->

now both are still move from left to right but go running down the x axis.

If someone could point me in the right direction I would be great full.

Lucus

#1
05/11/2008 (6:06 am)
Hello Lucus,
It's not clear to me what your looking to do.
Rather then post an answer that might further confuse the thread.. Can you explain this a bit differently?

Seems you want an object to move along a Path?
Want several instances of the object moving along the same path?
The objects travel further along the X axis with each new instance of the object?
#2
05/14/2008 (7:38 pm)
I think the problem is that when he adds more, they start moving further than he wants them to.
#3
05/15/2008 (2:39 pm)
Before I make any suggestion, we need a little more information.
This "shape" is a player? .. This "shape" is a projectile..or other simple shape?..
A little more detail is necessary because your answer will be better tailored when you can provide some specifics.

When dealing with objects .. it will either get a datablock or it won't..so the more detail you provide to this thread the better your answer can be.

Otherwise, I would simply link the thread to my other "Make Game" button post.
#4
05/16/2008 (10:53 am)
Thanks for all the post guys here is the code I was working on.


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Moving walls By Lucus Patrick  
//I used animshape.cs from the 3d Game Programing All In One second edition
//as a reffernce and start point.
//I created a custom Wall and used some Textures from Garage Games Dungeon Pack.

datablock StaticShapeData(M_Wall)                               
{
   category = "Moving_Walls";
   shapeFile = "~/data/shapes/SpikedWall1/spikedWallc.dts";
   myDistance = 0;     //This is a count of how many times the animShap is called.
   myDistanceb = 0;    //count of animBack

};


function m_Wall::OnAdd(%this,%shape,%obj)
{
    %this.DoAnimTest(%shape);

   //Dynamic variables added when the obj is placed 
   //with the world ediotr.
   //You can change these values in the Editor.  select object f3 find dynamic variables o false 1 true
   %shape.moveX = true;
   %shape.moveY = false;
   %shape.moveZ = false; 
   %shape.rotate = false; 
    
}

function M_Wall::AnimShape(%this,%shape,%dist,%angle)
// ----------------------------------------------------
//     moves the %shape by %dist amount, and then
//     schedules itself to be called again in 1/5
//     of a second.
// ----------------------------------------------------
{
  
  %transform = %shape.getTransform();  //Get the origonal positions transform values.
  
  %lx = getword(%transform,0);
  %ly = getword(%transform,1);         
  %lz = getword(%transform,2);
  %rx = getword(%transform,3);
  %ry = getword(%transform,4);
  %rz = getword(%transform,5);
  
  %tempdist = %shape.myDistance++;       //Increment distance everytime the function is called.
  
  //The following Statments check the dynamic variables
  //You can turn these of and on in the World Editor and use them howerver you like.
  // Proably could just do a switch!!

  if(%shape.moveX == true)
  {
     %lx += %dist;
   
  }   

  if(%shape.moveZ == true)
  {
     %lz += %dist;
  }

  if(%shape.moveY == true)
  {                
     %ly += %dist; 
  }
  
   if(%shape.rotate == true)
  {                
    %angle += 1.0;
    %rd = %angle; 
  }

  
 %shape.setTransform(%lx SPC %ly SPC %lz SPC        
                     %rx SPC %ry SPC %rz SPC %rd);


//This checks to see if the distance is at its max
//If tempdist has reached the max cancle the schedule function
//and call to animate the other way.

if(%tempdist == 10 && %shape.rotate == false) 
{
  cancel(%shapeAnim);
  %shape.myDistance = 0;                    //Needs to be zero for next call
  %this.Animback(%shape,%shape.distance );  //if its not set to zero than it will start were it left of last.
}
else
  %shapeAnim = %this.schedule(200,"AnimShape",%shape, %dist,%angle);  //call the function with a schedule


}

function m_wall::DoAnimTest(%this,%shape)
// ----------------------------------------------------
//     This Sets some dynamic variables and starts 
//     the animtion by calling AnimShape.
// ----------------------------------------------------
{
  
  %shape.distance = 0.5;    
  %shape.angleA   = 1.0;
  %this.AnimShape(%shape, %shape.distance, %shape.angleA  );

}


function m_wall::Animback(%this,%shape, %dist)
// ----------------------------------------------------
//     This is basicaly the same as the Anim shape
//     The only differnce is it is dercremnting to get
//     back to the orgional position
// ----------------------------------------------------
{
  
 
  %transform = %shape.getTransform();

  %lx = getword(%transform,0);   
  %ly = getword(%transform,1);         
  %lz = getword(%transform,2);
  %rx = getword(%transform,3);
  %ry = getword(%transform,4);
  %rz = getword(%transform,5);

  %tempDistb = %shape.myDistanceb++;
  
 if(%shape.moveX == true)
  {
      %lx -= %dist;
  }    
  
  if(%shape.moveZ == true)
  {
     %lz -= %dist;
  }   

  if(%shape.moveY == true)
  {                
     %ly -= %dist; 
  }

%shape.setTransform(%lx SPC %ly SPC %lz SPC 
                     %rx SPC %ry SPC %rz );


if(%tempDistb == 10)
{
   cancel(%shapeAnimb);
   %shape.myDistanceb = 0;
   %this.AnimShape(%shape, %shape.distance );
  
} 
else
  %shapeAnimb = %this.schedule(200,"Animback",%shape, %dist);
 

}
#5
05/16/2008 (10:56 am)
That code works!!!! I fixed my problem. check it out and play with it.

You just have to change the shape file or I can send you the spiked wall I am using.
It still has some other things I need to work out but what I was doing before works now.