TGB 1.7.3beta1 Bug - Text dismounting
by Patrick Shaw · in Torque Game Builder · 05/09/2008 (6:34 am) · 13 replies
I am using a t2dTextObject mounted to an object to display debug information about that object. After mounting the text object, I would update it in an "onUpdate" loop like this:
This works fine in 1.7.2. However, in 1.7.3, changing the text dismounts the text object from its parent.
function GridAlignAtRestBehavior::onUpdate(%this)
{
%this.debugTextObj.text = %this.owner.getPosition();
}This works fine in 1.7.2. However, in 1.7.3, changing the text dismounts the text object from its parent.
About the author
#2
05/09/2008 (7:47 am)
Sure. I'm setting the text in the first line of the "onUpdate" function.if (!isObject(GridAlignAtRestBehavior))
{
%template = new BehaviorTemplate(GridAlignAtRestBehavior);
%template.friendlyName = "Grid Align at rest";
%template.behaviorType = "AI";
%template.description = "Keeps the object aligned on the grid while it's at rest.";
}
function GridAlignAtRestBehavior::onAddToScene(%this)
{
%this.owner.enableUpdateCallback();
//%this.addDebugTextObject();
%this.debugTextObj = new t2dTextObject()
{
scenegraph = %this.owner.sceneGraph;
size = "11.925 2.000";
text = "Test this object";
font = "Arial";
wordWrap = "0";
hideOverflow = "0";
textAlign = "Left";
lineHeight = "2";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "24";
textColor = "1 1 1 1";
hideOverlap = "0";
};
%this.debugTextObj.mount(%this.owner, -1, -1);
%this.gridSize = 4;
%this.gridOffset = 2;
}
function GridAlignAtRestBehavior::onUpdate(%this)
{
//Stephen - comment the following line and the text object stays mounted
%this.debugTextObj.text = %this.owner.getPosition();
%xForce = 0;
%yForce = 0;
%xPos = %this.owner.getPositionX();
%yPos = %this.owner.getPositionY();
%xDelta = (%xPos) - mRound(%xPos);
%yDelta = %yPos - mRound(%yPos);
if (%this.getAtRestX() )
{
if(%xDelta != 0)
{
if (mAbs(%xDelta) < 0.1)
{
if (%this.getMomentumFacingX() == -1)
//choose next X grid to my left
%xPos = mFloor(%xPos / %this.gridSize) * %this.gridSize - %this.gridSize / 2;
else if (%this.getMomentumFacingX() == 1)
%xPos = mCeil(%xPos/ %this.gridSize) * %this.gridSize + %this.gridSize / 2;
else
%xPos = mRound(%xPos/ %this.gridSize) * %this.gridSize;
%this.owner.setPositionX(%xPos);
}
else
{
%xForce = -1 * %xDelta * 10.0;
}
}
}
%this.owner.setImpulseForce(%xForce, %yForce);
%this.setMomentumFacing();
}
function GridAlignAtRestBehavior::getAtRest(%this)
{
if (%this.getatRestX() && %this.getatRestY())
return true;
else
return false;
}
function GridAlignAtRestBehavior::getAtRestX(%this)
{
if (%this.owner.getlinearVelocityX() == 0 )
return true;
else
return false;
}
function GridAlignAtRestBehavior::getAtRestY(%this)
{
if (%this.owner.getlinearVelocityY() == 0 )
return true;
else
return false;
}
function GridAlignAtRestBehavior::setMomentumFacing(%this)
{
//remember the last +/- X and Y velocities
if (%this.owner.getlinearVelocityX() > 0)
%this.momentumFacingX = 1;
else if (%this.owner.getlinearVelocityX() < 0)
%this.momentumFacingX = -1;
else
%this.momentumFacingX = 0;
if (%this.owner.getlinearVelocityY() > 0)
%this.momentumFacingY = 1;
else if (%this.owner.getlinearVelocityY() < 0)
%this.momentumFacingY = -1;
}
function GridAlignAtRestBehavior::getMomentumFacingX(%this)
{
return %this.momentumFacingX;
}
function GridAlignAtRestBehavior::getMomentumFacingY(%this)
{
return %this.momentumFacingY;
}
#3
Tell me, do you see the problem if you turn "autoSize" off and "wordWrap" on?
If that solves it then I thing it's the "autoSize" function reasserting its position and because you're seeing it on the "onUpdate", you're effectively resetting its position to the pre-tick position. In other words, it never gets to move. It's still mounted but that position is overrident.
The text object reasserts its position/size when the text is changed because it has a text alignment option.
It should be a minor fix if that's the case.
Melv.
05/09/2008 (9:27 am)
I had a similar report quite a while ago that the t2dTextObject wasn't working when mounted in much the same way you mentioned. I thought I had fixed it but I may have missed a case.Tell me, do you see the problem if you turn "autoSize" off and "wordWrap" on?
If that solves it then I thing it's the "autoSize" function reasserting its position and because you're seeing it on the "onUpdate", you're effectively resetting its position to the pre-tick position. In other words, it never gets to move. It's still mounted but that position is overrident.
The text object reasserts its position/size when the text is changed because it has a text alignment option.
It should be a minor fix if that's the case.
Melv.
#4
Turning turn "autoSize" off and "wordWrap" on does fix the problem. Thanks!
05/09/2008 (9:32 am)
Melv,Turning turn "autoSize" off and "wordWrap" on does fix the problem. Thanks!
#5
I'll fix that up now.
Melv.
05/09/2008 (9:34 am)
Yeah, I just tried your code example with a down-counter that stops setting the text after 100 iterations and after that the text-object jumps to its correct mounted position so it does appear that its the "autosize" option suppress tick-based movement.I'll fix that up now.
Melv.
#6
Thanks for the report.
Melv.
05/09/2008 (9:41 am)
The bug reference is TGB-83. The repository reference is [x16/#8922].Thanks for the report.
Melv.
#7
a simple mount between 2 t2dStaticSprite that works great on 1.7.2 behaves erratically in 1.7.3.
I'll try to get a simple project as an example.
Eyal.
05/29/2008 (11:16 am)
Are there any other changes in the mount method between 1.7.2 and 1.7.3?a simple mount between 2 t2dStaticSprite that works great on 1.7.2 behaves erratically in 1.7.3.
I'll try to get a simple project as an example.
Eyal.
#8
This seems to compete with the mount() and bounce around between it's worldLimit and its mounted position. in 1.7.2 it was sticking to the mount position and somehow ignore the worldLimit.
In any case.... a simple setWorldLimit("NULL",-50,-37.5,50,37.5,"false") seems to fix that issue.
05/29/2008 (11:41 am)
My bad, it's not directly related to the mount method. the object that I'm mounting has a SetWorldLimit("clamp"...).This seems to compete with the mount() and bounce around between it's worldLimit and its mounted position. in 1.7.2 it was sticking to the mount position and somehow ignore the worldLimit.
In any case.... a simple setWorldLimit("NULL",-50,-37.5,50,37.5,"false") seems to fix that issue.
#9
In the case of a world-limit and a mount, which should it choose? It sounds like you've got a competitive setup but you'd have to confirm that.
If there is a bug here I'd like to understand it though so any info you could provide would be helpful.
Melv.
05/30/2008 (11:40 am)
I'm a little confused. Are you saying that you're nowhere near the world limits and they somehow affect the mounting of an object? Or are you saying that you're moving outside of the world-limit (which you've set) and it's competing between your mount instruction and the world-limit or perhaps something else?In the case of a world-limit and a mount, which should it choose? It sounds like you've got a competitive setup but you'd have to confirm that.
If there is a bug here I'd like to understand it though so any info you could provide would be helpful.
Melv.
#10
object A has a worldLimit and is mounted to object B. if object B is outside A's worldLimit , than A starts to frick out. seems reasonable to me... A is trying to maintain it's mount and worldLimit so it bounces around between them.
As soon as I set the worldLimit to "NULL" it mounts to B with no issues. this works for me. All I had to do is cancel the worldLimit once I mount it.
I do believe though that in 1.7.2 it didn't bounce around and just moved with the mounted object, ignoring it's worldLimit.
05/30/2008 (11:59 am)
I don't think it's a bug, but rather competitive setup.object A has a worldLimit and is mounted to object B. if object B is outside A's worldLimit , than A starts to frick out. seems reasonable to me... A is trying to maintain it's mount and worldLimit so it bounces around between them.
As soon as I set the worldLimit to "NULL" it mounts to B with no issues. this works for me. All I had to do is cancel the worldLimit once I mount it.
I do believe though that in 1.7.2 it didn't bounce around and just moved with the mounted object, ignoring it's worldLimit.
#11
One final question would be if the mount is rigid or not. Technically, a rigid-one is the competitive conflict but a non-rigid one could in theory honour both. Not sure if it currently would.
Melv.
05/30/2008 (1:13 pm)
Ah okay, I understand. I believe maybe the ordering of process since then may have affected that but in this case, freaking out should be the correctly behaviour ... let's call is a feature. ;)One final question would be if the mount is rigid or not. Technically, a rigid-one is the competitive conflict but a non-rigid one could in theory honour both. Not sure if it currently would.
Melv.
#12
I just tried it with a non-rigid mount and it seems to respect both forces. it still jiggles a bit back and forth , but maybe with the right mount force applied it can be smooth out.
I've also noticed that the mount force pulls stronger when object B (parent) is moving. when it's not moving the wordLimit seems to pull stronger. It's definitely a feature, I think it's AI :)
05/30/2008 (1:50 pm)
It is a rigid mount and I see your point.I just tried it with a non-rigid mount and it seems to respect both forces. it still jiggles a bit back and forth , but maybe with the right mount force applied it can be smooth out.
I've also noticed that the mount force pulls stronger when object B (parent) is moving. when it's not moving the wordLimit seems to pull stronger. It's definitely a feature, I think it's AI :)
Torque 3D Owner Stephen Zepp
I'm a bit mystified at what could be causing this problem, so any additional information would be helpful.