Author Topic: Sort of sight range search.  (Read 1297 times)

What I'm trying to do is add something to gameConnection::onDeath that makes every player do a sort of search to see if they can see the player who died and who killed the player. There could also be a first, instant search and another search a bit later to confirm if they saw or not.

I'm thinking this is possible with raycasts or some container search of some sort, but I don't know where to begin to do this.

A raycast from each player's eyepoint to a lower point of the killed player.

I'm going to sleep or doing something else so if you'll need an example I'll get to that later.

A raycast from each player's eyepoint to a lower point of the killed player.

I'm going to sleep or doing something else so if you'll need an example I'll get to that later.
I was thinking of a simple raycast but then it occured me that they'd have to be looking straight at the player.

Unless I'm not getting what you're saying.

I was thinking of a simple raycast but then it occured me that they'd have to be looking straight at the player.

Unless I'm not getting what you're saying.
What I'm suggesting would work even if the player died behind you... so maybe it's not very ideal either.

What I'm suggesting would work even if the player died behind you... so maybe it's not very ideal either.
You can grab the position from the raycast collision and then work out if its within 180 degrees of the players eye point.

You can grab the position from the raycast collision and then work out if its within 180 degrees of the players eye point.
what kind of maths involved in this

You can grab the position from the raycast collision and then work out if its within 180 degrees of the players eye point.
I know there was a weapon that did this except from behind...
How do you do it?

what kind of maths involved in this
1. Get the eye point of the player.
2. Cast a raycast towards the killer.
3. If it doesn't collide, they aren't seen.
4. If it collides, get the position from the raycast.
5. Find the angle (yaw) between the player's eyepoint and the raycast's collision position.
6. If the killer is within 180 degrees (probably not how much real humans can see but ohwell) then they can be seen.

The only problem is working out whether the angle is 180 degrees infront or 180 degrees behind.
Let me see if I can get a script working.

1. Get the eye point of the player.
2. Cast a raycast towards the killer.
3. If it doesn't collide, they aren't seen.
4. If it collides, get the position from the raycast.
5. Find the angle (yaw) between the player's eyepoint and the raycast's collision position.
6. If the killer is within 180 degrees (probably not how much real humans can see but ohwell) then they can be seen.

The only problem is working out whether the angle is 180 degrees infront or 180 degrees behind.
Let me see if I can get a script working.

If I could find that knife it'd be a lot easier.

Code: [Select]
function Player::objectInView(%player,%object)
{
if(!isObject(%object))
return 0;


//The eye point is the position of the players camera
%eye = %player.getEyePoint();
//The position of the object
%to = posFromTransform(%object.getTransform());

//Uncomment this if you want a max range for the player to be in view
//if(vectorDist(%eye,%to) < %range)
// return 0;

//Cast a raycast to try and collide with the object
%ray = containerRaycast(%eye,%to,$TypeMasks::StaticShapeObjectType | $TypeMasks::TerrainObjectType | $TypeMasks::VehicleObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::FxBrickObjectType | $TypeMasks::InteriorObjectType,%player);
%col = getWord(%ray,0);
if(isObject(%col) && %col == %object)
{
//The position of the collision
%pos = posFromRaycast(%ray);

//Super Maths C skills go B)
%resultant = vectorSub(%pos,%eye);
%normal = vectorNormalize(%resultant);

//Find the yaw from the resultant
%resultRadians = mAtan(getWord(%normal,1),getWord(%normal,0));

//Find the yaw from the eye vector
%eyeVec = %player.getEyeVector();
%eyeRadians = mAtan(getWord(%eyeVec,1),getWord(%eyeVec,0));

//Convert both of them to degrees for easier understanding
%resultDegrees = mRadToDeg(%resultRadians);
%eyeDegrees = mRadToDeg(%eyeRadians);

//Now the tricky part. In order for the object to be in sight, lets say that the object needs to be within 90 degrees of the players view
//Change 90 to something smaller if you don't like how wide the view is
if(%resultDegrees >= %eyeDegrees - 90 && %resultDegrees <= %eyeDegrees + 90)
return 1;
}
//No object hit, or not the target object, return 0/false
return 0;
}
Here's the script. I'm really happy with it, it worked for me first go and I worked it all out manually using the stuff I've learnt at school.

But since we're trying to see if they can see a dead player (corpse object type) wouldn't you have to add that mask in the list?

Oh and maybe replace the '90 degrees' rule with an arg.

Thanks, I really stink at vector logic sorts of things.

i also need to know how to disable death CI
« Last Edit: July 07, 2011, 05:35:55 PM by otto-san »

Thanks, I really stink at vector logic sorts of things.

i also need to know how to disable death CI
Package messageClient and check if the second arg == 'MsgClientDeath'