Blockland Forums > Modification Help

Sort of sight range search.

Pages: << < (2/3) > >>

otto-san:


--- Quote from: Destiny/Zack0Wack0 on July 06, 2011, 05:27:33 AM ---You can grab the position from the raycast collision and then work out if its within 180 degrees of the players eye point.

--- End quote ---
what kind of maths involved in this

Chrono:


--- Quote from: Destiny/Zack0Wack0 on July 06, 2011, 05:27:33 AM ---You can grab the position from the raycast collision and then work out if its within 180 degrees of the players eye point.

--- End quote ---
I know there was a weapon that did this except from behind...
How do you do it?

Destiny/Zack0Wack0:


--- Quote from: otto-san on July 06, 2011, 01:23:00 PM ---what kind of maths involved in this

--- End quote ---
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.


Chrono:


--- Quote from: Destiny/Zack0Wack0 on July 06, 2011, 11:08:58 PM ---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.


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

Destiny/Zack0Wack0:


--- Code: ---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;
}

--- End code ---
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.

Pages: << < (2/3) > >>

Go to full version