Game Development Community

Weapon/Ammo Picking it up with a keybind?!?

by Derek · in Technical Issues · 05/18/2006 (3:30 pm) · 2 replies

Like alot of FPS when you run over an object you just pick it up, I would like instead for the player to look at the object, or be in a very close vicinity of the object then to press a keybind to pick up and add the weapon to the inventory. I can get half of my problem fixed my self, by removing the on:col function for items, for a quick fix. Then how would I go about doing what I described above?

#1
05/18/2006 (3:35 pm)
Well you'll need to setup some method to do the search. I use something similiar myself.

How i did this was doing a radius container search for a certain distance.
Then i wrote a method to see how close it was to the player and the angle difference between them.
I'll dig up my code and post it.

function findsearch(%obj){

%position = %obj.getTransform();
%radius = 1;
%lastdist=99;
%searchMasks = $TypeMasks::PlayerObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::StaticTSObjectType;
InitContainerRadiusSearch(%position, %radius, %searchMasks);
	while ((%targetObject = containerSearchNext()) != 0){

		%dist = containerSearchCurrRadiusDist();
		echo("Current: "@%dist);
		echo("found object ",%targetObject);


//Check to see if it's something we can search or not
		if (%dist<%lastdist){
			if (%targetObject.Searchable){
				//Ok, it's close,but am i looking at it?
				%angle=getangle(%obj,%targetObject);
				error("angle: "@%angle);
				if (%angle<30){
					%validTarget=%targetObject;
					%lastdist = %dist;
				}
			}
		}
		echo("Last: "@%lastdist);
		}
	
	return %validTarget;
}

Here's the search function i wrote. It's got a few custom things in there like a Searchable tag, and a getangle function. but it should give you an idea.
#2
05/18/2006 (8:00 pm)
So, there is no way you could drop this in unless I defined your getangle and search tag things in the source code. Otherwise does anyone know a better way to go about doing this?