|
|
#1 |
|
I like turtles
![]() Join Date: Jan 2006
Location: Slovenia
Posts: 531
Reputation: 345
|
First of all, discard the "UP" vector, the only vector of use currently is the FRONT vector.
The FRONT vector is simply a unit length (1 unit) vector direction in which the player is aiming from the camera position. How to make sense of this..: Basically, if you add camera front vector to the camera position vector, you will get another point in game space which is exactly 1 unit apart from the player and is in the direction where the player is looking at. That camera target point can be then moved forward and backwards to have a point of reference against a specific target and see if the player is aiming towards it. Example usage: 1. calculate distance from camera position to target check position (say a specific object) 2. rescale the front vector so it's length will be the distance to object to check, THIS IS VERY EASY - Since the vector is always of 1.0 length you can simply multiply the front vector XYZ values by the distance from #1, we will call this vector a tempcamtarget vector. 3. Now since you have the tempcamtarget point that is of known distance away from the target point and towards what the player is looking at, you can do a simple distance check from the tempcamtarget to the object position, the distance returned will be how far off from target object the player is looking, so you can know if he's looking at a certain object, or looking away from it. EXAMPLE CODE: Code:
Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) {
new Float:TGTDistance;
// get distance from camera to target
TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
new Float:tmpX, Float:tmpY, Float:tmpZ;
tmpX = FrX * TGTDistance + CamX;
tmpY = FrY * TGTDistance + CamY;
tmpZ = FrZ * TGTDistance + CamZ;
return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}
Code is untested, but compiles and should work. |
|
|
|
|
|
#2 |
|
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2008
Location: Northern Ireland
Posts: 2,724
Reputation: 204
|
From this can we calculate a vehicle in front of the players distance/players distance simply by looking at it?
|
|
|
|
|
|
#3 | |
|
I like turtles
![]() Join Date: Jan 2006
Location: Slovenia
Posts: 531
Reputation: 345
|
Quote:
|
|
|
|
|
|
|
#4 |
|
Huge Clucker
![]() ![]() ![]() Join Date: Apr 2007
Posts: 413
Reputation: 3
|
Will be waiting for your example code.
( More upgrades to my zombie script =D ) |
|
|
|
|
|
#5 | ||
|
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2008
Location: Northern Ireland
Posts: 2,724
Reputation: 204
|
Quote:
|
||
|
|
|
|
|
#6 |
|
I like turtles
![]() Join Date: Jan 2006
Location: Slovenia
Posts: 531
Reputation: 345
|
CODE EDITED - THIS IS CORRECT AND TESTED!
Code:
Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) {
new Float:TGTDistance;
// get distance from camera to target
TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
new Float:tmpX, Float:tmpY, Float:tmpZ;
tmpX = FrX * TGTDistance + CamX;
tmpY = FrY * TGTDistance + CamY;
tmpZ = FrZ * TGTDistance + CamZ;
return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}
Code:
// EXAMPLE USAGE:
checkforcamera(PlayerID) {
new Float:CameraPos[3];
new Float:CameraFront[3];
new Float:CheckObjectPos[3] = {-2661.2764,915.7676,79.6685}; // trash can near partyserver torenos
GetPlayerCameraPos(PlayerID, CameraPos[0], CameraPos[1], CameraPos[2]);
GetPlayerCameraFrontVector(PlayerID, CameraFront[0], CameraFront[1], CameraFront[2]);
new Float:distc;
distc = DistanceCameraTargetToLocation(CameraPos[0], CameraPos[1], CameraPos[2], CheckObjectPos[0], CheckObjectPos[1], CheckObjectPos[2], CameraFront[0], CameraFront[1], CameraFront[2]);
new string[128];
if (distc < 2.0) {
format(string,sizeof(string),"YOU SEE IT.");
SendClientMessage(PlayerID, COLOR_RED, string);
}
return true;
}
|
|
|
|
|
|
#7 |
|
Huge Clucker
![]() ![]() ![]() Join Date: Nov 2007
Posts: 425
Reputation: 2
|
pawn Code:
Use radius 1.0 for players |
|
|
|
|
|
#8 |
|
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Nov 2008
Location: Somerset, England
Posts: 2,032
Reputation: 16
|
Thanks, RedShirt. Good post.
|
|
|
|
|
|
#9 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Apr 2009
Location: San Fierro
Posts: 665
Reputation: 1
|
Hmm this might sound noobish but
im trying IsPlayerAimingAt in a command but im not sure if im doing it correct. Can someone give an example ? |
|
|
|
|
|
#10 | |
|
I like turtles
![]() Join Date: Jan 2006
Location: Slovenia
Posts: 531
Reputation: 345
|
Quote:
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Vectors | potato | Help Archive | 1 | 08/08/2010 05:09 AM |
| Camera Help | TKZ227 | Help Archive | 1 | 04/06/2010 11:24 PM |
| camera pos | Kar | Help Archive | 8 | 03/06/2010 08:12 AM |
| Camera Help | CharlieScene | Help Archive | 3 | 13/04/2010 05:46 PM |
| Please Read >>>> How To Add Play Class Selection Music? <<<< Please Read | DeltaAirlines12 | Help Archive | 8 | 15/08/2009 10:41 PM |