Game Development Community

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.

#1
04/26/2010 (5:26 am)
Well, you're never telling the Item to start moving - until you do it manually in the console. If you want the target to move, you've gotta call the method on it, and that's not being done at the moment.

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.