Game Development Community

Key bind to pick up item

by Richard Preziosi · in Torque Game Engine · 05/22/2010 (10:16 pm) · 9 replies

So I have implemented the following resource into 1.5.2 to attempt to add the item interactivity which i desire.

http://www.torquepowered.com/community/resources/view/9687

It works in a sense, however I'm not understanding how to make it interact with "items". It is only showing the interact crosshair on interior buildings. When it comes to ammo clips, weapons and health kits and you press the interact key it is just showing the number of the terrain.

I've tried $TypeMasks::ItemObjectType, $TypeMasks::ShapeBaseObjectType and neither have worked.

What I am getting towards is the ability to put the crosshair over an item, it be a "pickup-able" item and have the interact key pick it up. I've found lots of threads saying to implement a container ray cast, but nothing saying a basic way of doing anything after you have achieved that.

Any help would be greatly appreciated, thanks.

#1
05/23/2010 (1:36 pm)
So after a bit of banging my head against the monitor I was able to figure out that the health packs, potions, and clips that come with the engine don't have a collision mesh. Going to work on that and see if i can't get this going. Will post my progress as I go incase anyone is able to help.
#2
05/23/2010 (2:26 pm)
Not looked at the code but if it's using raycasts you will need a collision mesh and bounding box and --- very small colmeshes can easily get missed by raycasts. So you might want to make them bigger than realistically required.
#3
05/23/2010 (2:53 pm)
yea it's a container ray cast method, and it took hours of figuring out, but you are correct, no collision mesh = no go. Just moved and haven't set computer up yet, being lazy, but excited to see if i can get it going now knowing what the "main" problem was.
#4
05/23/2010 (5:05 pm)
Ok so i got the items to finally be "interactable", and this is what I'm down to. Here is the code I am using in an attempt to "pickup" the item in question on keypress.
function onInteractWith(%client, %objID)
{

  %obj = %client.resolveObjectFromGhostIndex(%objID);
  echo("(SERVER) INTERACTING WITH " @ %obj);

  if(%obj.getType() & $TypeMasks::PlayerObjectType)
  {
      echo("Your Death Stare does " @ %obj.getShapeName() @ " 200 points of damage! ZAP!");
      %obj.applyDamage(200);     
  }
  
  if(%obj.getType() & $TypeMasks::ItemObjectType)
  {
      echo("using item");
      %obj.onPickup();     
  }
}

Here is the error I am getting
starter.fps/server/scripts/commands.cs (86): Unknown command onPickup.
  Object (1544) Item -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject

I'm guessing that there is a bit wrong with my code, is ItemObjectType the correct mask? I only assumed this since ItemObjectType is in the C++ and the items are flagged as "items".

Any help greatly appreciated.
#5
05/23/2010 (7:25 pm)
Is "onPickup" a function? Is it "pickup"? Should the whole thing be handled from the client who is doing the picking up? "client.player.pickup(%obj);" ? etc

Don't have TGE anymore, so I can't look at the code...
#6
05/24/2010 (1:57 am)
You are absolutely correct, it needs to be "%client.player.pickup(%obj);" though. Thanks a lot.

Part of my problem was that I was trying to pick up health patches, which I found out through another problem I was having that health patches are not set up correctly for that, ammo clips were though so I got that working.
#7
05/24/2010 (12:43 pm)
Quote:Part of my problem was that I was trying to pick up health patches, which I found out through another problem I was having that health patches are not set up correctly for that, ammo clips were though so I got that working.
Health patches are set up that way by design.
// Health Kits are designed to be picked up and stored in the player's
// inventory until they "use" it. This differs from the Health Patches below
// that apply immediately on collision with a wounded player.
Healthpatches have a unique onCollision method which overrides the Item namespace method - simply remove that and they should be compatible with your interact method just as the ammo items are.
#8
05/24/2010 (2:18 pm)
Yeah I just changed everything from health patches to health kits and it all performs beautifully. Yeah I just wish I would have realized that about health patches before I spent so much time beating myself up.
#9
05/24/2010 (2:27 pm)
Oh but the rewards of learning, right ;)

The whole health kit/patch thing was a holdover from Tribes, and not many games used similar behavior so it's not an obvious thing that most people think of.