Moving in Object
by Harrison Brock · in Torque Game Builder · 08/25/2006 (2:13 pm) · 2 replies
I have 10 buckets on my screen and I have a ball mount to one of them. I would like to move the ball to a other buckets if its in a distance of 5X or 5Y.
function bucket::onAdd(%this)
{
//Array Set
$buckets[bucketcount] = %this;
$bucketcount++;
}
//Get X and Y Position
for(%i=0; %i<=$bucketcount; %i++)
{
$buckets[%i].getPositionX();
$buckets[%i].getPositionY();
}
I need something like this to move the ball
if bucket has a ball on
Check the position of all other bucket that are 5X or 5Y from the bucket with the ball on it
find bucket
ball.dismount();
move ball to new bucket
ball.mount(new bucktet, 0,0,0 true,false,false);
What would be the best way to do this?
Thanks
Harrison Brock
function bucket::onAdd(%this)
{
//Array Set
$buckets[bucketcount] = %this;
$bucketcount++;
}
//Get X and Y Position
for(%i=0; %i<=$bucketcount; %i++)
{
$buckets[%i].getPositionX();
$buckets[%i].getPositionY();
}
I need something like this to move the ball
if bucket has a ball on
Check the position of all other bucket that are 5X or 5Y from the bucket with the ball on it
find bucket
ball.dismount();
move ball to new bucket
ball.mount(new bucktet, 0,0,0 true,false,false);
What would be the best way to do this?
Thanks
Harrison Brock
#2
This is assuming %ballbucket is the index of the bucket with the ball.
This will only put the ball in the last bucket in the array that fits the description, not the closest bucket.
08/25/2006 (3:47 pm)
Oh code btw:This is assuming %ballbucket is the index of the bucket with the ball.
This will only put the ball in the last bucket in the array that fits the description, not the closest bucket.
for(%i=0; %i<=$bucketcount; %i++)
{
if (mAbs($buckets[%ballbucket].getPositionX()-$buckets[%i].getPositionX())<=5)
{
if (mAbs($buckets[%ballbucket].getPositionY()-$buckets[%i].getPositionY())<=5)
{
ball.dismount();
ball.setposition($buckets[%i].getPositionX(),$buckets[%i].getPositionY());
ball.mount($buckets[%i], 0,0,0 true,false,false);
}
}
}
Torque Owner Shane B.
You could use ball.setposition to move the ball to the other bucket, then mount it.