Car collision
by Zach · in Torque Game Engine · 08/02/2004 (6:41 am) · 9 replies
Using the starter.racing kit, and it appears that
function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
in car.cs
is never called. I want a vehicle to be able to pick up objects like healthpacks etc.
Do I need to mod the engine to get this working. Can't find a resource or code for this.
Also tried using a mounted player in the vehicle, but then the player is by default a lot smaller than the vehicle, so can't see how that can work.
Anybody got a mod or code snippet to get a vehicle detecting collisions with items?
or am I missing something??
Thanks
Z
function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
in car.cs
is never called. I want a vehicle to be able to pick up objects like healthpacks etc.
Do I need to mod the engine to get this working. Can't find a resource or code for this.
Also tried using a mounted player in the vehicle, but then the player is by default a lot smaller than the vehicle, so can't see how that can work.
Anybody got a mod or code snippet to get a vehicle detecting collisions with items?
or am I missing something??
Thanks
Z
#2
08/02/2004 (7:45 am)
This might be related to a bad typemask in the vehicle code.
#3
player.cc has...
static U32 sCollisionMoveMask = (TerrainObjectType | InteriorObjectType |
WaterObjectType | PlayerObjectType |
StaticShapeObjectType | VehicleObjectType |
PhysicalZoneObjectType | StaticTSObjectType);
static U32 sServerCollisionContactMask = (sCollisionMoveMask |
(ItemObjectType |
TriggerObjectType |
CorpseObjectType));
static U32 sClientCollisionContactMask = sCollisionMoveMask | PhysicalZoneObjectType;
wheras wheeledvehicle.cc has only got
static U32 sClientCollisionMask =
TerrainObjectType | InteriorObjectType |
PlayerObjectType | StaticShapeObjectType |
VehicleObjectType | VehicleBlockerObjectType |
StaticTSObjectType;
and thereafter, the collision detection routines appear to be quite different.
It certainly doesn't have "ItemObjectType" in the mask, which I guess is needed.
I don't suppose adding that will be enough will it?
08/02/2004 (7:50 am)
I'm not a C++ programmer, but I've noticed thatplayer.cc has...
static U32 sCollisionMoveMask = (TerrainObjectType | InteriorObjectType |
WaterObjectType | PlayerObjectType |
StaticShapeObjectType | VehicleObjectType |
PhysicalZoneObjectType | StaticTSObjectType);
static U32 sServerCollisionContactMask = (sCollisionMoveMask |
(ItemObjectType |
TriggerObjectType |
CorpseObjectType));
static U32 sClientCollisionContactMask = sCollisionMoveMask | PhysicalZoneObjectType;
wheras wheeledvehicle.cc has only got
static U32 sClientCollisionMask =
TerrainObjectType | InteriorObjectType |
PlayerObjectType | StaticShapeObjectType |
VehicleObjectType | VehicleBlockerObjectType |
StaticTSObjectType;
and thereafter, the collision detection routines appear to be quite different.
It certainly doesn't have "ItemObjectType" in the mask, which I guess is needed.
I don't suppose adding that will be enough will it?
#4
No need to mod the engine to get THAT part working.
I'm at work right now, but I'll see if I can dig through my files tonight and post something more helpful...
Or maybe dig up the resource that got me up and running.
08/02/2004 (8:01 am)
The functionality for damage and health additions is there by default.No need to mod the engine to get THAT part working.
I'm at work right now, but I'll see if I can dig through my files tonight and post something more helpful...
Or maybe dig up the resource that got me up and running.
#5
Ran a quick search on my own posts to try and remember how I got started.
Here is the thread where I started tracking down how to apply damage by collision, which if memory serves will detect collision with the health object and apply health accordingly.
Incidentally, the tutorial I refer to in this thread was written by BadGuy and can be found here.
~Hope this helps
08/02/2004 (8:07 am)
Addendum:Ran a quick search on my own posts to try and remember how I got started.
Here is the thread where I started tracking down how to apply damage by collision, which if memory serves will detect collision with the health object and apply health accordingly.
Incidentally, the tutorial I refer to in this thread was written by BadGuy and can be found here.
~Hope this helps
#6
08/02/2004 (10:23 am)
The other approach is to attach the ::onCollision to the object your interested in. So instead of the car handling it, the health kit would. I'm pretty sure that's what I did during my testing.
#7
08/02/2004 (1:57 pm)
It's good to see people sharing information. Nice work, Kirby and Brian. :)
#8
This is all using the standard buggy starter kit, and the added bits are taken from the FPS kit.
Firstly, you need to add healthkit.cs or a similar file to game.cs to define the datablock of the item you want to pick up, e.g. exec("./health.cs");
otherwise by default the engine appears to identify the healthkit or any other item as an obstruction in the same way as terrain. You also need to include item.cs and inventory.cs to allow the whole pickup procedure.
Add
maxInv[HealthKit] = 5;
to car.cs in the car datablock which allows the car to pick the healthpack up, otherwise it will assume that you already have your quota and will ignore it.
At this point the onCollision routine in car.cs will allow you pickup the healthpack
when you collide with it. Something like:
// Try and pickup all items
if (%col.getClassName() $= "Item") {
%obj.pickup(%col);
}
will do the job.
I'm assuming this is the correct way to go about this, but as I say I am new to this. If someone spots any errors, please let me know. Hope this helps others.
Zach
08/03/2004 (2:45 am)
Thanks for the replies on this. All appreciated. Although none of them solved the actual problem, it made me think that the engine has got the facility, so it just must be missing from the Buggy script kit. My initial interpretation was that the Torque engine was not even calling the WheeledVehicle::onCollision routine in car.cs, as echo's in that routine weren't appearing at all when I drove over a healthkit. However, it was/will be called, in a similar way to the collision routine in player.cs if the following bits are added, which are basically taken from the FPS starter kit and added to the buggy kit.This is all using the standard buggy starter kit, and the added bits are taken from the FPS kit.
Firstly, you need to add healthkit.cs or a similar file to game.cs to define the datablock of the item you want to pick up, e.g. exec("./health.cs");
otherwise by default the engine appears to identify the healthkit or any other item as an obstruction in the same way as terrain. You also need to include item.cs and inventory.cs to allow the whole pickup procedure.
Add
maxInv[HealthKit] = 5;
to car.cs in the car datablock which allows the car to pick the healthpack up, otherwise it will assume that you already have your quota and will ignore it.
At this point the onCollision routine in car.cs will allow you pickup the healthpack
when you collide with it. Something like:
// Try and pickup all items
if (%col.getClassName() $= "Item") {
%obj.pickup(%col);
}
will do the job.
I'm assuming this is the correct way to go about this, but as I say I am new to this. If someone spots any errors, please let me know. Hope this helps others.
Zach
#9
09/19/2006 (8:32 pm)
I'm trying to do the same thing in GameOne tutorial for racing stater kit. I mean about collison.Any idea how?
Torque Owner Bruno Grieco
Search the forums fot other posts regarding this problem,
Sorry I can't help you further.