Moving Items.
by Jon Oster · in Game Design and Creative Issues · 04/25/2010 (9:51 pm) · 1 replies
I'm making a game with moving targets however I'm not quite sure on how to make them move on the start up on the level. I have them moving if i manually call the item ID and call the function but i want the targets to be moving once the level loads.
Here is my Code.
****Target Item****
$jTarget1= new Item(Target) {
canSaveDynamicFields = "1";
Position = "416.658 256.389 220.276";
rotation = "0 0 1 90";
scale = "1 1 1";
dataBlock = "Targets";
collidable = "1";
static = "1";
rotate = "0";
};
****Moving Function****
//Goes back and forth 2 units every 4 seconds.
function movemeleft(%object){
%x = getword(%object.getposition(),0);
%y = getword(%object.getposition(),1);
%z = getword(%object.getposition(),2);
%newx = %x-2;
%object.setTransform(%newx SPC %y SPC %z) ;
schedule(400,0,"movemeright",%object);
}
function movemeright(%object){
%x = getword(%object.getposition(),0);
%y = getword(%object.getposition(),1);
%z = getword(%object.getposition(),2);
%newx = %x+2;
%object.setTransform(%newx SPC %y SPC %z) ;
schedule(400,0,"movemeleft",%object);
}
I feel i should just be able to call movemeleft($jTarget1); and have it move left to right that on launch but when i run it it doesn't move the target. Any insight would be much appreciated.
Here is my Code.
****Target Item****
$jTarget1= new Item(Target) {
canSaveDynamicFields = "1";
Position = "416.658 256.389 220.276";
rotation = "0 0 1 90";
scale = "1 1 1";
dataBlock = "Targets";
collidable = "1";
static = "1";
rotate = "0";
};
****Moving Function****
//Goes back and forth 2 units every 4 seconds.
function movemeleft(%object){
%x = getword(%object.getposition(),0);
%y = getword(%object.getposition(),1);
%z = getword(%object.getposition(),2);
%newx = %x-2;
%object.setTransform(%newx SPC %y SPC %z) ;
schedule(400,0,"movemeright",%object);
}
function movemeright(%object){
%x = getword(%object.getposition(),0);
%y = getword(%object.getposition(),1);
%z = getword(%object.getposition(),2);
%newx = %x+2;
%object.setTransform(%newx SPC %y SPC %z) ;
schedule(400,0,"movemeleft",%object);
}
I feel i should just be able to call movemeleft($jTarget1); and have it move left to right that on launch but when i run it it doesn't move the target. Any insight would be much appreciated.
Torque Owner Daniel Buckmaster
T3D Steering Committee
Look up the ItemData::onAdd callback - it runs whenever an object with a certain datablock is added to the scene. That's where you'd call your moving function.
Also, I'd recommend using pathed shapes rather than scheduling setTransform calls.