Rotate many object
by Harrison Brock · in Torque Game Builder · 08/17/2006 (11:59 am) · 4 replies
I have four object on screen. When I click on one of the object it will rotate to the left, but I need the other object to rotate to the right. What will be the best way to do this. Should I make aa simObject for what I have.
Harrison Brock
Harrison Brock
#2
function mole::onAdd(%this)
{
%this.setUseMouseEvents(true);
}
function mole::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%rotation = (%this.getRotation() + 90) % 360;
%this.setRotation(%rotation);
}
function mole::onRightMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%rotation = (%this.getRotation() - 90) % 360;
%this.setRotation(%rotation);
}
am just try to get the other 3 object to rotate in the other direction. I have try to uses the name of the object
like mole2.setRotation but that did not work
08/17/2006 (4:52 pm)
Here what I have for the first object.function mole::onAdd(%this)
{
%this.setUseMouseEvents(true);
}
function mole::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%rotation = (%this.getRotation() + 90) % 360;
%this.setRotation(%rotation);
}
function mole::onRightMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%rotation = (%this.getRotation() - 90) % 360;
%this.setRotation(%rotation);
}
am just try to get the other 3 object to rotate in the other direction. I have try to uses the name of the object
like mole2.setRotation but that did not work
#3
this is untested, and may or may not work ... not sure if when %rotation is -90 that -%rotation will be +90 or not, it should though ...
This would work, and probably provide decent enough performance with a small number of objects but would not work with hundreds or thousands though as I believe this loop would be 'over kill' and a better system would need to be used in it's place ...
This also does not take into account the removal of moles either, so you would have to write something to keep track of removing the moles. If you removed mole 3 from the $moles array, you would have to then shift the rest of the moles downward in the array ...
hope this helps
08/17/2006 (7:27 pm)
Harrison, give this a whirl;// this is outside of any functions
$moleCount = 0;
function mole::onAdd(%this)
{
$moles[$moleCount] = %this;
$moleCount++;
$moles[$moleCount].setUseMouseEvents(true);
}
function mole::onMouseDown(%this,...)
{
%rotation = // ...
%this.setRotation(%rotation);
for(%x=0;%x<$moleCount;%x++)
{
if($moles[%x] != %this)
{
$moles[%x].setRotation(-%rotation);
}
}
}
}this is untested, and may or may not work ... not sure if when %rotation is -90 that -%rotation will be +90 or not, it should though ...
This would work, and probably provide decent enough performance with a small number of objects but would not work with hundreds or thousands though as I believe this loop would be 'over kill' and a better system would need to be used in it's place ...
This also does not take into account the removal of moles either, so you would have to write something to keep track of removing the moles. If you removed mole 3 from the $moles array, you would have to then shift the rest of the moles downward in the array ...
hope this helps
#4
08/17/2006 (7:51 pm)
Thanks to all. Am just us the moles for testing of something that am work on.
Torque Owner Shane B.
Like
box1.angularvelocity(10);
box2.angularvelocity(-10);