Simple problem
by Anthony Ratcliffe · in Torque Game Builder · 01/25/2008 (6:01 pm) · 9 replies
I'm trying to create a scrolling space invaders type movement however i cant seem to find a break command
%this.setLinearVelocityX(-20); // moves along
%this.setLinearVelocityX(0); // stops
%this.setLinearVelocityY(5); // moves down 5
%this.setLinearVelocityY(0); // stops
%this.setLinearVelocityX(20); // moves back in opp direction
this doesnt seem to work insted it reachs the end then gets to move down 5 and jst continues till it goes off screen. ideally i want
moves along
stops
moves down for five
moves in opp direction
any help plz
ant
%this.setLinearVelocityX(-20); // moves along
%this.setLinearVelocityX(0); // stops
%this.setLinearVelocityY(5); // moves down 5
%this.setLinearVelocityY(0); // stops
%this.setLinearVelocityX(20); // moves back in opp direction
this doesnt seem to work insted it reachs the end then gets to move down 5 and jst continues till it goes off screen. ideally i want
moves along
stops
moves down for five
moves in opp direction
any help plz
ant
About the author
#2
01/25/2008 (6:15 pm)
A question... let me know if I'm understanding what you mean by a "break" command... do you mean a command that stop the script logic until the object has moved down 5 units, then move 20 in the x (zeroing out the Y).
#3
01/25/2008 (11:24 pm)
One way to do this would be to use a combination of schedules, moveTo and onPositionTarget commands. I'm not sure how else you can do it. There's no animation timeline in TGB like you see in Flash or other programs, so it's hard to create more complex movements. You'll have to do it with clever scripting.
#4
do you mean a command that stop the script logic until the object has moved down 5 units
just looking at the refrence guide and finding it hard to read, anyone got an example?
01/26/2008 (6:06 pm)
Matt was spot on saying do you mean a command that stop the script logic until the object has moved down 5 units
just looking at the refrence guide and finding it hard to read, anyone got an example?
#5
In this case, you might just want to have a list of coordinates that you'd like them to visit and then have it moveTo() each of those in sequence. When they reach that point, onPositionTarget() is called, which should then send them to the next point. When
01/26/2008 (9:59 pm)
The script as it is will just take those commands as fast as it can, which will clearly change the state of your object quicker than you'd intended. In this case, you might just want to have a list of coordinates that you'd like them to visit and then have it moveTo() each of those in sequence. When they reach that point, onPositionTarget() is called, which should then send them to the next point. When
#6
01/27/2008 (7:10 am)
Could i not use paths to do this?
#7
setPositionTarget(%targetX, %targetY, [%autoStop = true], [%callback =
false], [%snap = true], [%margin = 0.1])
Purpose
Sets a target position for the object.
Syntax
%targetX - Float
The x position of the target.
%targetY - Float
The y position of the target.
%autoStop - Bool
Whether or not the object should stop upon reaching the target.
%callback - Bool
Whether or not to execute the onPositionTarget() callback when the target is reached.
%snap - Bool
Whether or not to snap the object to the target position when it is within the margin.
%margin - Float
The proximity to the target necessary to qualify as reaching the target.
Notes
* This function does not actually move the object. Instead, it allows an object to be stopped
or execute a callback upon reaching a destination position. To have an object
automatically move to a target position, use moveTo().
moveTo(%targetX, %targetY, %speed, [%autoStop = true], [%callback =
false], [%snap = true], [%margin = 0.1])
Purpose
Sets a target position for the object and moves it toward that target.
Syntax
%targetX - Float
The x position of the target.
%targetY - Float
The y position of the target.
%speed - Float
The speed at which the object is sent to the target.
%autoStop - Bool
Whether or not the object should stop upon reaching the target.
%callback - Bool
Whether or not to execute the onPositionTarget() callback when the target is reached.
%snap - Bool
Whether or not to snap the object to the target position when it is within the margin.
%margin - Float
The proximity to the target necessary to qualify as reaching the target.
Notes
* The object is not actually forced to the target position, it is merely sent there. So, if a
collision or some other outside force interferes with the object, it may not make it to the
target position. However, the target is still set, so the object may still reach the target in the
does that mean to i work out the cordinates i'm a bit confused? or do i set a dynamic field to store say the 4 points i want it to move to
moveTo(%targetX, %targetY, [%autoStop = true],
{
cordinates 47,43
}
somthing like that
01/28/2008 (10:58 am)
Ok just found a refrence to position and move tosetPositionTarget(%targetX, %targetY, [%autoStop = true], [%callback =
false], [%snap = true], [%margin = 0.1])
Purpose
Sets a target position for the object.
Syntax
%targetX - Float
The x position of the target.
%targetY - Float
The y position of the target.
%autoStop - Bool
Whether or not the object should stop upon reaching the target.
%callback - Bool
Whether or not to execute the onPositionTarget() callback when the target is reached.
%snap - Bool
Whether or not to snap the object to the target position when it is within the margin.
%margin - Float
The proximity to the target necessary to qualify as reaching the target.
Notes
* This function does not actually move the object. Instead, it allows an object to be stopped
or execute a callback upon reaching a destination position. To have an object
automatically move to a target position, use moveTo().
moveTo(%targetX, %targetY, %speed, [%autoStop = true], [%callback =
false], [%snap = true], [%margin = 0.1])
Purpose
Sets a target position for the object and moves it toward that target.
Syntax
%targetX - Float
The x position of the target.
%targetY - Float
The y position of the target.
%speed - Float
The speed at which the object is sent to the target.
%autoStop - Bool
Whether or not the object should stop upon reaching the target.
%callback - Bool
Whether or not to execute the onPositionTarget() callback when the target is reached.
%snap - Bool
Whether or not to snap the object to the target position when it is within the margin.
%margin - Float
The proximity to the target necessary to qualify as reaching the target.
Notes
* The object is not actually forced to the target position, it is merely sent there. So, if a
collision or some other outside force interferes with the object, it may not make it to the
target position. However, the target is still set, so the object may still reach the target in the
does that mean to i work out the cordinates i'm a bit confused? or do i set a dynamic field to store say the 4 points i want it to move to
moveTo(%targetX, %targetY, [%autoStop = true],
{
cordinates 47,43
}
somthing like that
#8
{
$node=0;
%this.setPositionTarget(48,-30, true, true);
%this.setLinearVelocityX(15);
$node++;
}
//goes along 15
function si::onPositionTarget(%this)
{
if ($node==1)
{
%this.setPositionTarget(48,-28, true, true);
echo ("reached call2");
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(2);
$node++;
}
else if ($node==2)
{
echo ("reached call3");
%this.setPositionTarget(48,-26, true, true);
%this.setLinearVelocityX(-15);
%this.setLinearVelocityY(0);
$node++;
}
else if ($node==3)
{
%this.setPositionTarget(-46,-24, true, true);
echo ("reached call4");
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(2);
$node++;
}
else if ($node==4)
{
echo ("reached call5");
%this.setPositionTarget(-46,-26, true, true);
%this.setLinearVelocityX(15);
%this.setLinearVelocityY(0);
$node++;
}
}
ok i got it to move however node 3 and 4 wont call any ideas
02/01/2008 (6:49 am)
Function si::onLevelLoaded(%this){
$node=0;
%this.setPositionTarget(48,-30, true, true);
%this.setLinearVelocityX(15);
$node++;
}
//goes along 15
function si::onPositionTarget(%this)
{
if ($node==1)
{
%this.setPositionTarget(48,-28, true, true);
echo ("reached call2");
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(2);
$node++;
}
else if ($node==2)
{
echo ("reached call3");
%this.setPositionTarget(48,-26, true, true);
%this.setLinearVelocityX(-15);
%this.setLinearVelocityY(0);
$node++;
}
else if ($node==3)
{
%this.setPositionTarget(-46,-24, true, true);
echo ("reached call4");
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(2);
$node++;
}
else if ($node==4)
{
echo ("reached call5");
%this.setPositionTarget(-46,-26, true, true);
%this.setLinearVelocityX(15);
%this.setLinearVelocityY(0);
$node++;
}
}
ok i got it to move however node 3 and 4 wont call any ideas
#9
02/08/2008 (5:03 pm)
Bump plz
Torque 3D Owner Matthew Langley
Torque