Author Topic: Checking in a triangle.  (Read 2324 times)

the best solution for this would probably be to do a single boxsearch that encompasses the entire volume of the cone, then do some math on any objects it picks up to test whether or not they are actually in the cone. this would be difficult mathwise, but its probably the most efficient and the most accurate way to do it.

im not too sure how to test if a certain point is inside a cone or not, but one way would be to find out how far away from the muzzle the object is according to the center line of the cone (this most likely requires trig), then use that distance to calculate the radius of the cone at that distance using a cone equation (im sure you can find one on google or wikipedia), then see if the object is in that radius, probably using vectordist(pos1,pos2).

@ exidyne:

A radius search searches a sphere, defined by the center point and radius you give it.

With initContainerBoxSearch is the position the center of the box of the bottom corner?

Also with the scale wouldn't the x & y have to change dependant on which direction they're facing?
« Last Edit: January 08, 2008, 11:47:19 AM by MrPickle »

If you did a box search, the %pos is the center of the box, not the corner.  So

Code: [Select]
initContainerBoxSearch(%player.position,"2.5 2.5 3",$TypeMasks::PlayerObjectType);
would search for players in an area 5 bricks wide, 5 bricks long, and 5 bricks tall around the player.

Ok, thank.

If I do some stuff to make the box come from the muzzle point, which I'm pretty sure I'd be able to do, Would I have to change the x and y axis dependant on the direction the player is facing?

Yes you would, I'll try and calculate it now.

Randy and Trader and Zor win. :D

Good luck on basing your box search off the muzzle point.  I don't know how you'd obtain the position of the muzzle point to use as the starting position for the search.

Code: [Select]
%player.getMuzzlePoint(%slot);
%player.getMuzzleVector(%slot);

Nice.

Too bad there's no way to adjust the angle of the box search based on your muzzle vector.

You might want to use a radius search instead.  That way, your results are more consistent.

Crap I forgot about you being able to look up and down