Author Topic: Centering a polyhedron on a bot  (Read 1725 times)

I recently coded something with someone the past couple of days and ran into a problem. First of all, the polyhedron I created is not centered on the bot, rather it is shown like so:



How would I go about centering the polyhedron so it wraps the bot?

To add onto that, whenever I enter the zone, the center print does not print, but I created an echo to test whenever you would enter the zone, and that worked. Could someone please help me out? I'd rather avoid spoon-feeding and receive a clear demonstration.

Here is the code:

Code: [Select]
// trader bot hole information
datablock fxDTSBrickData (BrickTraderBot_HoleSpawnData)
{
brickFile = "Add-ons/Bot_Hole/4xSpawn.blb";
category = "Special";
subCategory = "Holes";
uiName = "Trader Hole";
iconName = "Add-Ons/Bot_Blockhead/icon_blockhead";

bricktype = 2;
cancover = 0;
orientationfix = 1;
indestructable = 1;

isBotHole = 1;
holeBot = "traderHoleBot";
};

datablock PlayerData(TraderHoleBot : PlayerStandardArmor)
{
uiName = "";
canJet = 0;
maxItems   = 0;
maxWeapons = 0;
maxTools = 0;
runforce = 100 * 90;
maxForwardSpeed = 8;
maxBackwardSpeed = 4;
maxSideSpeed = 8;
rideable = false;
canRide = false;
isInvincible = true;
isHoleBot = 1;
hIdle = 1;
 hIdleLookAtOthers = 1;
};


//snazzy trader
function TraderHoleBot::onAdd(%this, %obj, %botData, %bot)
{
Armor::onAdd(%this, %obj);

%obj.llegColor =  "0.392157 0.196078 0 1";
%obj.secondPackColor =  "0.388235 0 0.117647 1";
%obj.lhand =  "0";
%obj.hip =  "0";
%obj.faceName =  "smileyPirate2";
%obj.rarmColor =  "0.901961 0.341176 0.0784314 1";
%obj.hatColor =  "1 1 1 1";
%obj.hipColor =  "0.200 0.200 0.200 1.000";
%obj.chest =  "0";
%obj.rarm =  "0";
%obj.packColor =  "0.2 0 0.8 1";
%obj.pack =  "0";
%obj.decalName =  "Mod-Suit";
%obj.larmColor =  "0.901961 0.341176 0.0784314 1";
%obj.secondPack =  "0";
%obj.larm =  "0";
%obj.chestColor =  "0.901961 0.341176 0.0784314 1";
%obj.accentColor =  "0.000 0.200 0.640 0.700";
%obj.rhandColor =  "1 0.878431 0.611765 1";
%obj.rleg =  "0";
%obj.rlegColor =  "0.392157 0.196078 0 1";
%obj.accent =  "0";
%obj.headColor =  "1 0.878431 0.611765 1";
%obj.rhand =  "0";
%obj.lleg =  "0";
%obj.lhandColor =  "1 0.878431 0.611765 1";
%obj.hat =  "0";

GameConnection::ApplyBodyParts(%obj);
GameConnection::ApplyBodyColors(%obj);

%obj.tradeZone = new Trigger()
{
position = %obj.spawnBrick.getPosition();
datablock = TraderTriggerData;
scale = "5 5 4";
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
};
}


datablock TriggerData(TraderTriggerData)
{
className = "TraderTrigger";
tickPeriodMS = 100;
};

function TraderTrigger::onEnterTrigger(%triggerData, %trigger, %client)
{
centerPrint(%client, "\c5You cannot take damage in this zone.", 5);
echo("Zone entered!");
}

function TraderTrigger::onLeaveTrigger(%triggerData, %trigger, %client)
{
centerPrint(%client, "\c5You have left the zone. You are now able to take damage.", 5);
echo("Zone left!");
}

package TraderActivate
{
function Player::Activatestuff(%obj)
{
Parent::Activatestuff(%obj);
%object =  getWord(containerRaycast(%obj.getEyePoint(),vectorAdd(%obj.getEyePoint(),vectorScale(%obj.getEyeVector(),3)),$Typemasks::playerObjectType,%obj), 0);

if(isObject(%object))
{
%playerData = %object.getDataBlock();

if(%playerData == TraderHoleBot.getId())
{
MessageClient(%obj.getControllingClient(), "", "\c5Trader:\c6 Hello, check out my variety of wares.");
}
}
}
};
activatePackage(TraderActivate);

The position of a trigger is the lower left corner of it. Offset it by half it's size to the side.

Try %client.centerprint( instead

The position of a trigger is the lower left corner of it. Offset it by half it's size to the side.
Which number do I offset exactly? I'm not very familiar with how to work polyhedrons.

edit:
Try %client.centerprint( instead
What is the rest of this? I can't find anything related to this, I can only find centerPrint(%client, %message, %time);.
Found something else.
« Last Edit: April 29, 2014, 07:29:12 PM by YK »

Replace it with position = vectorsub(%obj.spawnbrick.getposition(), "2.5 2.5 0);

Also I'm pretty sure onentertrigger doesn't give you a client as 3rd argument, but the object that hit it
So you'll first need to check whether it is a player and then get its client


Alright, I got everything to work, here is the fixed code for anyone wondering. Thank you Zeblote.

Code: [Select]
// trader bot hole information
datablock fxDTSBrickData (BrickTraderBot_HoleSpawnData)
{
brickFile = "Add-ons/Bot_Hole/4xSpawn.blb";
category = "Special";
subCategory = "Holes";
uiName = "Trader Hole";
iconName = "Add-Ons/Bot_Blockhead/icon_blockhead";

bricktype = 2;
cancover = 0;
orientationfix = 1;
indestructable = 1;

isBotHole = 1;
holeBot = "traderHoleBot";
};

datablock PlayerData(TraderHoleBot : PlayerStandardArmor)
{
uiName = "";
canJet = 0;
maxItems   = 0;
maxWeapons = 0;
maxTools = 0;
runforce = 100 * 90;
maxForwardSpeed = 8;
maxBackwardSpeed = 4;
maxSideSpeed = 8;
rideable = false;
canRide = false;
isInvincible = true;
isHoleBot = 1;
hIdle = 1;
 hIdleLookAtOthers = 1;
};


//snazzy trader
function TraderHoleBot::onAdd(%this, %obj, %botData, %bot)
{
Armor::onAdd(%this, %obj);

%obj.llegColor =  "0.392157 0.196078 0 1";
%obj.secondPackColor =  "0.388235 0 0.117647 1";
%obj.lhand =  "0";
%obj.hip =  "0";
%obj.faceName =  "smileyPirate2";
%obj.rarmColor =  "0.901961 0.341176 0.0784314 1";
%obj.hatColor =  "1 1 1 1";
%obj.hipColor =  "0.200 0.200 0.200 1.000";
%obj.chest =  "0";
%obj.rarm =  "0";
%obj.packColor =  "0.2 0 0.8 1";
%obj.pack =  "0";
%obj.decalName =  "Mod-Suit";
%obj.larmColor =  "0.901961 0.341176 0.0784314 1";
%obj.secondPack =  "0";
%obj.larm =  "0";
%obj.chestColor =  "0.901961 0.341176 0.0784314 1";
%obj.accentColor =  "0.000 0.200 0.640 0.700";
%obj.rhandColor =  "1 0.878431 0.611765 1";
%obj.rleg =  "0";
%obj.rlegColor =  "0.392157 0.196078 0 1";
%obj.accent =  "0";
%obj.headColor =  "1 0.878431 0.611765 1";
%obj.rhand =  "0";
%obj.lleg =  "0";
%obj.lhandColor =  "1 0.878431 0.611765 1";
%obj.hat =  "0";

GameConnection::ApplyBodyParts(%obj);
GameConnection::ApplyBodyColors(%obj);

%obj.tradeZone = new Trigger()
{
position = vectorsub(%obj.spawnBrick.getPosition(), "2.5 2.5 0");
datablock = TraderTriggerData;
polyhedron = "0 0 0 5 0 0 0 5 0 0 0 4";
};
}


datablock TriggerData(TraderTriggerData)
{
className = "TraderTrigger";
tickPeriodMS = 100;
};

function TraderTrigger::onEnterTrigger(%triggerData, %trigger, %player)
{
centerPrint(%player.getControllingClient(), "\c5You cannot take damage in this zone.", 5);
echo("Zone entered!");
}

function TraderTrigger::onLeaveTrigger(%triggerData, %trigger, %player)
{
centerPrint(%player.getControllingClient(), "\c5You have left the zone. You are now able to take damage.", 5);
echo("Zone left!");
}

package TraderActivate
{
function Player::Activatestuff(%obj)
{
Parent::Activatestuff(%obj);
%object =  getWord(containerRaycast(%obj.getEyePoint(),vectorAdd(%obj.getEyePoint(),vectorScale(%obj.getEyeVector(),3)),$Typemasks::playerObjectType,%obj), 0);

if(isObject(%object))
{
%playerData = %object.getDataBlock();

if(%playerData == TraderHoleBot.getId())
{
MessageClient(%obj.getControllingClient(), "", "\c5Trader:\c6 Hello, check out my variety of wares.");
}
}
}
};
activatePackage(TraderActivate);

I don't exactly know for sure, but doesn't .gethackposition() get the center of an object? Correct me if I'm wrong, I haven't used it before.

Player::getHackPosition() will get the dead center of a player object. Note that it will not work for other objects; for other objects you can use SimObject::getWorldboxCenter() to get the dead center of the object.

Player::getHackPosition() will get the dead center of a player object. Note that it will not work for other objects; for other objects you can use SimObject::getWorldboxCenter() to get the dead center of the object.
Thank you for that

Player::getHackPosition() will get the dead center of a player object. Note that it will not work for other objects; for other objects you can use SimObject::getWorldboxCenter() to get the dead center of the object.

SimObject::getWorldboxCenter() should also work for players, unless Torque is stupid.

SimObject::getWorldboxCenter() should also work for players, unless Torque is stupid.
It does, but it returns a slightly different value than Player::getHackPosition() on the Z axis.

SimObject::getWorldboxCenter() should also work for players, unless Torque is stupid.

The player model or the bounding box specified for it is weird, not Torque.
Try opening the mission editor and selecting a player. The world box is massive.