Author Topic: Trying to get a vectorDist that's even with square corners and middle of sides  (Read 2201 times)

I'm trying to get a simple collision detector that will be on a flat plane for a gamemode I'm working on (onPlayerTouch isn't doing what I need it to fast enough with multiple triggers).



I need the middle of those sides to be 12 like the corners are, but I'm clueless on how to do that.

Code: [Select]
function Player::checkVector(%this)
{

%brick = _test;

%pos = getWords(%this.getPosition(),0,1) SPC getWord(%brick.getPosition(),2);
%dist = vectorDist(%pos,%brick.getPosition());

return %dist;
}

Or if there's some function that doesn't apply to the onPlayerTouch delay, that would be fine too.

http://en.wikipedia.org/wiki/Taxicab_geometry



function manhattanDistance(%a, %b)
{
    %x = mAbs(getWord(%a, 0) - getWord(%b, 0));
    %y = mAbs(getWord(%a, 1) - getWord(%b, 1));
    %z = mAbs(getWord(%a, 2) - getWord(%b, 2));

    return %x + %y + %z;
}

-snip-
Corners are now 16, middle of sides are still 8. :c
I need all of these even or some replacement onPlayerTouch function

Use triggers or manual overlap checks (use FxDTSBrick::getWorldBox and check if Player::getPosition is inside it).

(use FxDTSBrick::getWorldBox and check if Player::getPosition is inside it).
didn't even think of doing that afdsdsf
Code: [Select]
function Player::checkIfPresent(%this)
{
%brick = _test;

%pos = %this.getPosition();
%box = %brick.getWorldBox();
%boxMin = vectorAdd(getWords(%box,0,2),"-0.7 -0.7 -0.7");
%boxMax = vectorAdd(getWords(%box,3,5),"0.7 0.7 0.7");

if(getWord(%pos,0) >= getWord(%boxMin,0) && getWord(%pos,0) <= getWord(%boxMax,0))
if(getWord(%pos,1) >= getWord(%boxMin,1) && getWord(%pos,1) <= getWord(%boxMax,1))
if(getWord(%pos,2) >= getWord(%boxMin,2) && getWord(%pos,2) <= getWord(%boxMax,2))
return 1;

return 0;
}

This works fine, thanks :P
I had to get it to extend out 0.7 in all directions for some reason so that it detected my player object, but eh it works

Wait, although you've already solved it, could you explain your problem a bit more? Im having difficulty following it. Did you want to detect if players were on (or above/below?) the brick, or if they were within a radius of the brick, where the radius is the distance from a corner to the center?

Wait, although you've already solved it, could you explain your problem a bit more? Im having difficulty following it. Did you want to detect if players were on (or above/below?) the brick, or if they were within a radius of the brick, where the radius is the distance from a corner to the center?
I needed something similar to onPlayerTouch that wasn't relying on the brick for the function. I needed it to rely on an AIPlayer so that the player triggers it at a regular interval, rather than the brick triggering it at a regular interval.

That and it needs to happen for each AIPlayer touching it.
Code: [Select]
function AIPlayer::isTouchingCore(%this)
{
%brick = $CoreDefense::CoreBrick;

%pos = %this.getPosition();
%box = %brick.getWorldBox();
%boxMin = vectorAdd(getWords(%box,0,2),"-0.7 -0.7 -0.7");
%boxMax = vectorAdd(getWords(%box,3,5),"0.7 0.7 0.7");
%boxDiff = vectorSub(%boxMax,%boxMin);

if(getWord(%pos,0) >= getWord(%boxMin,0) && getWord(%pos,0) <= getWord(%boxMax,0))
if(getWord(%pos,1) >= getWord(%boxMin,1) && getWord(%pos,1) <= getWord(%boxMax,1))
if(getWord(%pos,2) >= getWord(%boxMin,2) && getWord(%pos,2) <= getWord(%boxMax,2))
return 1;

return 0;
}

function AIPlayer::checkCoreCollision(%this)
{
cancel(%this.zombieCore);
%corebrick = $CoreDefense::CoreBrick;

if(%this.isTouchingCore() && %this.dataBlock.maxDamage - %this.getDamageLevel() > 0)
{
%corebrick.coreHealth -= ((0.05+%corebrick.coreLevel/160) - %corebrick.coreDef);
changeEnvironment(%corebrick.coreHealth/%corebrick.coreMaxHealth);
%corebrick.setLight(redLight);
%corebrick.schedule(80,setLight,blueLight);
serverPlay2D(CoreHurtSound);

%corebrick.setBrickName("Core --" SPC %corebrick.getCoreHealthStr() SPC "/" SPC %corebrick.coreMaxHealth @ ".0" SPC "HP");

if(%corebrick.coreHealth <= 0)
endCDRound(1);
}

%this.zombieCore = %this.schedule(2000,checkCoreCollision);
}

Use triggers. TDM and Slayer both use them for capture points, which seems to be similar to the functionality you want.

Code: [Select]
function fxDtsBrick::createTrigger(%this,%data,%polyhedron) //please rename me!
{
if(!isObject(%data))
{
Slayer_Support::Error("fxDtsBrick::createTrigger","Trigger datablock not found.");
return 0;
}

if(%polyhedron $= "")
%polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";

%trigger = new Trigger()
{
brick = %this;
datablock = %data;
polyhedron = %polyhedron;
};
missionCleanup.add(%trigger);

%boxMax = getWords(%this.getWorldBox(), 3, 5);
%boxMin = getWords(%this.getWorldBox(), 0, 2);
%boxDiff = vectorSub(%boxMax,%boxMin);
%boxDiff = vectorAdd(%boxDiff,"0 0 0.2");
%trigger.setScale(%boxDiff);

%posA = %this.getWorldBoxCenter();
%posB = %trigger.getWorldBoxCenter();
%posDiff = vectorSub(%posA, %posB);
%posDiff = vectorAdd(%posDiff, "0 0 0.1");
%trigger.setTransform(%posDiff);

return %trigger;
}

You should be fine if you just use the default polyhedron.


A polyhedron is a 3D geometric shape with flat faces and straight edges.

In TorqueScript, I believe that the %polyhedron variable is a list of relative coordinates.

This is the polyhedron:
Code: [Select]
0 0 0 1 0 0 0 -1 0 0 0 1
It breaks down into these coordinates:
Code: [Select]
0 0 0
1 0 0
0 -1 0
0 0 1
//I'm fairly confident that you can use a different number of coordinates, depending on what shape you want.

The coordinates describe the outer bounds of the shape, although I'm not sure exactly what point they refer to.

The coordinates describe the outer bounds of the shape, although I'm not sure exactly what point they refer to.

Relative coordinates? For example, the 2D polyhedron "0 0 -1 -1 1 1" refers to the following coordinates:

Code: [Select]
0 0
-1 -1
1 1

Where X is the centroid of the trigger (and also point 0), and numbers represent points of the polyhedron:

1..
.X.
..2

Relative coordinates? For example, the 2D polyhedron "0 0 -1 -1 1 1" refers to the following coordinates:

Code: [Select]
0 0
-1 -1
1 1

Where X is the centroid of the trigger (and also point 0), and numbers represent points of the polyhedron:

1..
.X.
..2


Right, that's what I said. The question is what points of the polyhedron? I would assume they are the vertices.