Coin/Vehicle collision
by starwize · in Torque Game Engine · 04/13/2005 (7:00 pm) · 8 replies
I can't get the score to increase when I run over a coin in a vehicle (works fine on foot). Here is the collision in coins.cs:
function Gold::onCollision(%this,%obj,%col)
{
echo("Coin collision %this = " @ %this @ " %obj = " @ %obj @ " %col = " @ %col);
if (%col.getDataBlock().className $= Armor)
%col.client.Score += %this.scoreValue;
echo("score");
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!',
%this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%col.client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;
echo("Coin Pickup failed");
}
As I said, this works fine. The following is the collision code in car.cs (it displays the 'You have picked up a coin' part but doesn't add the value to the score):
function WheeledVehicle::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects, including items
// need to set this up later
if (%col.getClassName() $= Coins) {
%obj.getMountNodeObject(0).pickup(%col);
%col.getMountNodeObject(0).client.Score += %this.scoreValue;
echo("score");
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!',
%this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%col.getMountNodeObject(0).client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;
}
}
Any ideas?
function Gold::onCollision(%this,%obj,%col)
{
echo("Coin collision %this = " @ %this @ " %obj = " @ %obj @ " %col = " @ %col);
if (%col.getDataBlock().className $= Armor)
%col.client.Score += %this.scoreValue;
echo("score");
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!',
%this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%col.client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;
echo("Coin Pickup failed");
}
As I said, this works fine. The following is the collision code in car.cs (it displays the 'You have picked up a coin' part but doesn't add the value to the score):
function WheeledVehicle::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects, including items
// need to set this up later
if (%col.getClassName() $= Coins) {
%obj.getMountNodeObject(0).pickup(%col);
%col.getMountNodeObject(0).client.Score += %this.scoreValue;
echo("score");
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!',
%this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%col.getMountNodeObject(0).client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;
}
}
Any ideas?
#2
function Gold::onCollision(%this,%obj,%col)
{
echo("Coin collision %this = " @ %this @ " %obj = " @ %obj @ " %col = " @ %col);
{
if (%col.getDataBlock().className $= Armor )
{
%col.client.Score += %this.scoreValue;
echo("score");
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!',
%this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%col.client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;
}
else if(%col.getDataBlock().className $= WheeledVehicle)
{
%client = %col.getMountNodeObject(0).client;
%client.Score += %this.scoreValue;
echo("score");
messageClient(%client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!',
%this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;
}
}
echo("Coin Pickup failed");
}
The player picks it up fine, with console message, hud message, and increased score. But when I run over the coin in a vehicle there is no hud message and the score goes blank (console says 'score, picked up a coin').
04/14/2005 (10:25 am)
I changed the gold collision code to the second line above and it had no effect. I've taken the collision out of car.cs and put it in coins.cs, it looks like this now:function Gold::onCollision(%this,%obj,%col)
{
echo("Coin collision %this = " @ %this @ " %obj = " @ %obj @ " %col = " @ %col);
{
if (%col.getDataBlock().className $= Armor )
{
%col.client.Score += %this.scoreValue;
echo("score");
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!',
%this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%col.client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;
}
else if(%col.getDataBlock().className $= WheeledVehicle)
{
%client = %col.getMountNodeObject(0).client;
%client.Score += %this.scoreValue;
echo("score");
messageClient(%client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!',
%this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;
}
}
echo("Coin Pickup failed");
}
The player picks it up fine, with console message, hud message, and increased score. But when I run over the coin in a vehicle there is no hud message and the score goes blank (console says 'score, picked up a coin').
#3
Also might want to check and make sure the pickup radius in your Player and Car datablocks are the same or similar.
04/14/2005 (10:30 am)
Just curious but you DO have collision boxes on both objects right?Also might want to check and make sure the pickup radius in your Player and Car datablocks are the same or similar.
#4
ALSO this has been already answers serveral months ago, if you check the forums you should be able to find the exact changes needed.
04/14/2005 (10:31 am)
You need to add VehicleObjectType to the item's collision in the C, recompile and then it should work. . . ALSO this has been already answers serveral months ago, if you check the forums you should be able to find the exact changes needed.
#5
Yes, collision boxes are there. I'll check the pickup raduis (I beleive it is the same for both).
@Anthony
I'm using the 'Vehicle Resource' to create the mountable vehicle and I've been using this post to try and make it work:
http://www.garagegames.com/mg/forums/result.thread.php?qt=24532
I've tried just about every way but it just doesn't work. As far as adding VehicleObjectType, do I add this to Item.cc?
04/14/2005 (12:30 pm)
@DreamerYes, collision boxes are there. I'll check the pickup raduis (I beleive it is the same for both).
@Anthony
I'm using the 'Vehicle Resource' to create the mountable vehicle and I've been using this post to try and make it work:
http://www.garagegames.com/mg/forums/result.thread.php?qt=24532
I've tried just about every way but it just doesn't work. As far as adding VehicleObjectType, do I add this to Item.cc?
#6
04/14/2005 (1:08 pm)
Do me/us a favor post the datablocks which show where you are declaring coins, players and vehicles and if at all possible show the code where you are implementing them with one or two surrounding lines of code. This would be very helpful in trying to wrap the ole' brain around the problem.
#7
an alternative could be
if(%col.getType & $TypeMasks::VehicleObjectType)
04/14/2005 (2:23 pm)
Yeah post the datablocks, make sure the vehicle's classname is WheeledVehiclean alternative could be
if(%col.getType & $TypeMasks::VehicleObjectType)
#8
datablock ShapeBaseImageData(GoldImage)
{
shapeFile = "~/data/models/items/kash1000.dts";
item = Gold;
lightType = "PulsingLight";
lightColor = "1.0 0.2 0.2 1.0";
lightTime = "1000";
lightRadius = "7";
cloakable = false;
};
datablock ItemData(Gold)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
// classname = Item;
category = "Coins";
image = GoldImage;
// Basic Item properties
shapeFile = "~/data/models/items/kash1000.dts";
mass = 0.7;
friction = 0.8;
elasticity = 0.3;
computeCRC = true;
lightType = "PulsingLight";
lightColor = "1.0 0.2 0.2 1.0";
lightTime = "1000";
lightRadius = "7";
respawnTime = 30 * 60000;
salvageTime = 15 * 60000;
// Dynamic properties defined by the scripts
pickupName = "a gold coin";
scoreValue = 1000;
};
Here's the code from plaugui.gui:
new GuiTextCtrl(score) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "559 4";
extent = "100 20";
minExtent = "8 8";
visible = "1";
text = "0";
maxLength = "255";
helpTag = "0";
};
In car.cs, the classname is made:
datablock WheeledVehicleData(DefaultCar)
{
classname = WheeledVehicle;
category = "Vehicles";
shapeFile = "~/data/shapes/car/buggy.dts";
emap = true;
04/14/2005 (5:33 pm)
Here's the gold coin datablock (in coins.cs):datablock ShapeBaseImageData(GoldImage)
{
shapeFile = "~/data/models/items/kash1000.dts";
item = Gold;
lightType = "PulsingLight";
lightColor = "1.0 0.2 0.2 1.0";
lightTime = "1000";
lightRadius = "7";
cloakable = false;
};
datablock ItemData(Gold)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
// classname = Item;
category = "Coins";
image = GoldImage;
// Basic Item properties
shapeFile = "~/data/models/items/kash1000.dts";
mass = 0.7;
friction = 0.8;
elasticity = 0.3;
computeCRC = true;
lightType = "PulsingLight";
lightColor = "1.0 0.2 0.2 1.0";
lightTime = "1000";
lightRadius = "7";
respawnTime = 30 * 60000;
salvageTime = 15 * 60000;
// Dynamic properties defined by the scripts
pickupName = "a gold coin";
scoreValue = 1000;
};
Here's the code from plaugui.gui:
new GuiTextCtrl(score) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "559 4";
extent = "100 20";
minExtent = "8 8";
visible = "1";
text = "0";
maxLength = "255";
helpTag = "0";
};
In car.cs, the classname is made:
datablock WheeledVehicleData(DefaultCar)
{
classname = WheeledVehicle;
category = "Vehicles";
shapeFile = "~/data/shapes/car/buggy.dts";
emap = true;
Torque Owner Ed Johnson
might have to be
or something to that effect