Getting "item" class to be warpable?
by Brown Student (#0013) · in Torque Game Engine · 12/17/2007 (4:06 pm) · 1 replies
Hello, i am making this post to see if anyone is knowledgable on getting "item" class object to be able to warp to a designated spawn marker.
I have to use "item" class because it seemed to be the only way to be able to push my object via propulsion physics.
My game is a mix of pool and mini golf. I have the player charge then "push/shoot" the cue ball based the following scriptings:
datablock ItemData(cueball)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
shapeFile = "~/data/shapes/finalGame/cueball.dts";
category = "gameObjects";
mass = 1;
friction = 1;
elasticity = 0.3;
emap = true;
};
function ItemData::create(%data)
{
// The mission editor invokes this method when it wants to create
// an object of the given datablock type. For the mission editor
// we always create "static" re-spawnable rotating objects.
%obj = new Item() {
dataBlock = %data;
static = false;
rotate = false;
};
return %obj;
}
AND
function fire(%power)
{
%power = LocalClientConnection.power;
%dir = LocalClientConnection.player.getForwardVector();
commandToServer('HitBall', cueBallObj, %dir, %power);
}
function buildPower()
{
LocalClientConnection.power++;
if (LocalClientConnection.power > 40)
{
LocalClientConnection.power = 40;
}
$Sched_Power = schedule(100, MissionGroup, buildPower);
}
function powerKey(%val)
{
if ( %val )
buildPower();
else
cancel($Sched_Power);
}
moveMap.bind( keyboard, space, powerKey );
moveMap.bindCmd( mouse, button1, "fire();", "LocalClientConnection.power = 0;");
AND THE TRIGGER
function HoleinOneTrigger::onEnterTrigger( %this, %trigger, %obj )
{
echo( "You have invaded the trigger!");
schedule(500, %trigger.target, nextHole, %trigger.target);
Parent::onEnterTrigger( %this, %trigger, %obj );
}
function nextHole(%target)
{
%ball = ServerConnection.ball;
// ball tp
%ball.setTransform(%target.getTransform());
// player move, with offset
}
function serverCmdHitBall(%client, %ball, %dir, %power)
{
%newVector = VectorScale(%dir, %power);
%ball.applyImpulse(%ball.getWorldBoxCenter(), %newVector);
}
Now a normal trigger does not recognize the cue ball when it is hit into it. The echos do not go off but if i walk through it as the player they do. From all I have read and was told normal triggers can't be used with the "item" class that torque uses.
I am unsure how to set up a onCollision that would allow the cue ball to warp the the spawn marker at the next hole using the "item" class.
All I can assume is that somewhere in a function the "item" (cueball), warp end spot (spawnmarker) and possibly the actual object used for the collision need to be defined in some manner.
If anyone understands any of this please respond with any kind of help you can.
thanks
I have to use "item" class because it seemed to be the only way to be able to push my object via propulsion physics.
My game is a mix of pool and mini golf. I have the player charge then "push/shoot" the cue ball based the following scriptings:
datablock ItemData(cueball)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
shapeFile = "~/data/shapes/finalGame/cueball.dts";
category = "gameObjects";
mass = 1;
friction = 1;
elasticity = 0.3;
emap = true;
};
function ItemData::create(%data)
{
// The mission editor invokes this method when it wants to create
// an object of the given datablock type. For the mission editor
// we always create "static" re-spawnable rotating objects.
%obj = new Item() {
dataBlock = %data;
static = false;
rotate = false;
};
return %obj;
}
AND
function fire(%power)
{
%power = LocalClientConnection.power;
%dir = LocalClientConnection.player.getForwardVector();
commandToServer('HitBall', cueBallObj, %dir, %power);
}
function buildPower()
{
LocalClientConnection.power++;
if (LocalClientConnection.power > 40)
{
LocalClientConnection.power = 40;
}
$Sched_Power = schedule(100, MissionGroup, buildPower);
}
function powerKey(%val)
{
if ( %val )
buildPower();
else
cancel($Sched_Power);
}
moveMap.bind( keyboard, space, powerKey );
moveMap.bindCmd( mouse, button1, "fire();", "LocalClientConnection.power = 0;");
AND THE TRIGGER
function HoleinOneTrigger::onEnterTrigger( %this, %trigger, %obj )
{
echo( "You have invaded the trigger!");
schedule(500, %trigger.target, nextHole, %trigger.target);
Parent::onEnterTrigger( %this, %trigger, %obj );
}
function nextHole(%target)
{
%ball = ServerConnection.ball;
// ball tp
%ball.setTransform(%target.getTransform());
// player move, with offset
}
function serverCmdHitBall(%client, %ball, %dir, %power)
{
%newVector = VectorScale(%dir, %power);
%ball.applyImpulse(%ball.getWorldBoxCenter(), %newVector);
}
Now a normal trigger does not recognize the cue ball when it is hit into it. The echos do not go off but if i walk through it as the player they do. From all I have read and was told normal triggers can't be used with the "item" class that torque uses.
I am unsure how to set up a onCollision that would allow the cue ball to warp the the spawn marker at the next hole using the "item" class.
All I can assume is that somewhere in a function the "item" (cueball), warp end spot (spawnmarker) and possibly the actual object used for the collision need to be defined in some manner.
If anyone understands any of this please respond with any kind of help you can.
thanks
Torque Owner Dracola
Therefore we must use something that collides with triggers, like a player. But having the hole be a player is pretty hackish. The option I would lean towards is having a floating projectile on the hole. Projectiles will collide with destructible items, so you would need to make your ball one. Of course you could have it never be destroyed and it would basically be the same thing. Then in the projectiles onCollide you would put all your code.
The alternative to this method is to go into the source code and create a new type of object for your ball if you're up to that.
If you have any questions, ask.