Game Development Community

Item collision

by Leslie Young · in Torque Game Engine · 02/20/2003 (12:26 pm) · 11 replies

Is there a way to get the player to collide against Items? (Items like Weapon and Ammo)

I created a rock item that the player must be able to pick up when standing front of it and pressing a key (got this to work, I also deleted the code in player::onColl... where he would auto pickup the item when running over it).

What I need is the player to also be able to collide against this object as he can just run through it now. The objet's collision info is ok as I tested it as a static object and collision worked, just seems like there is no collision for Items? or is there and I'm just being stupid?

Ive been going through the code and tried various things the whole day and now I'm really ... please help me with this one.

#1
02/20/2003 (12:34 pm)
hmm I swear there was a time when the collidable flag option of items worked..

tho I cannot at this time get it to stop the player.
you can however see the players current weapon react to it.
#2
02/20/2003 (12:38 pm)
Yhe I did mess around with that flag and added some code in the player object to check if it was set but then I got the player colliding against a bounding box (the box around the object you see when editing the world)
#3
02/20/2003 (6:38 pm)
I ran into a similar problem with my 'ammoboxes' in TZ - I dug for just a bit, didn't figure it out immediately, and just implemented it in scripting (which was cool, since I wanted to do a couple o' other things with 'em too)

Anyway - in the oncollision event, grab the object that collided with it -

function AmmoCrate::onCollision(%datablock, %this,%obj,%col,%vec,%speed)
{

   %this.setVelocity(%obj.getVelocity());
   %vel1 = getword(%obj.getVelocity(), 0);
   %vel2 = getword(%obj.getVelocity(), 1);
   %vel3 = getword(%obj.getVelocity(), 2);

You can just set it to zero, or, negative the velocity giving it a bit of a 'bounce' when it hits the rock.
#4
02/20/2003 (7:36 pm)
Is this assuming that something had been done in the modelling process so that the object has a collision mesh, or can you create the mesh in code?
#5
02/20/2003 (7:40 pm)
As far as I know, the model will have to have the collision mesh setup alread - I don't think you can make directly from code (though if I'm wrong I'm sure someone will correct me ;-)
#6
02/20/2003 (8:58 pm)
Is that something easily done in Max? I'm not the modeler on my team, but I wanna make sure he has the tools at his disposal..
#7
02/20/2003 (9:02 pm)
Yep - you'll have to check the docs on the Max exporter, but, in MS3D you just make a mesh that surrounds the object (however detailed you want, but, simple is probably better) and call it collision and export it. It may vary a bit for Max so be sure to take what I say with a grain of salt and double check in the exporter's docs ;-)
#8
02/21/2003 (9:38 am)
Cool, I thought about trying this in script, I'l have a look at that code snippet, thanx
#9
03/10/2003 (11:30 pm)
I'm working on pushable barrels at the moment.

In player.cc update the sCollisionMoveMask to include ItemObjectType, and players can no longer run through any item. Not sure if this is what I really want, so I'll probably keep hackin'

static U32 sCollisionMoveMask = (TerrainObjectType      | InteriorObjectType   |
                                 WaterObjectType        | PlayerObjectType     |
                                 StaticShapeObjectType  | VehicleObjectType    |
                                 ForceFieldObjectType | ItemObjectType |
                                 PhysicalZoneObjectType | StaticTSObjectType);
#10
03/11/2003 (10:56 am)
Yhe, I did that but then the player would collide with the bound box and that is not so accurate if the object is big or has different areas that can be collided with (not just a simple box type)

Well I see you found my resource about this and I'll try that code you suggested, though I dropped the project that needed that functionality, but I'll continue with it when my corrent (smaller) project is done.
#11
03/11/2003 (11:08 am)
Yeah. :)

(The resource in question for those who are curious is: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3937)

Another caveat with my snippet is that it doesn't support vehicle/item collisions. I was able to drive my "buggy" over a barrel last night without any problems. :-) More code to write I guess.