Skip to content

Commit

Permalink
Release 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Dec 26, 2022
2 parents a92c57c + 2a564e7 commit ec22cfc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripting/gravity-gun.sp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Plugin myinfo = {
name = "Gravity gun",
author = "Dron-elektron",
description = "Allows you to grab, move and throw players",
version = "1.4.0",
version = "1.4.1",
url = "https://github.com/dronelektron/gravity-gun"
};

Expand Down
1 change: 1 addition & 0 deletions scripting/include/gg/math.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
#define _gg_math_included

#define VECTOR_SIZE 3
#define HALF 0.5
21 changes: 17 additions & 4 deletions scripting/modules/math.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void Math_CalculateVelocityToDestination(int client, int target, float distance,

GetClientEyePosition(client, clientEyePosition);
GetClientEyeAngles(client, clientEyeAngles);
GetClientAbsOrigin(target, targetPosition);
Math_CalculatePlayerMiddle(target, targetPosition);
GetAngleVectors(clientEyeAngles, clientDirection, NULL_VECTOR, NULL_VECTOR);
ScaleVector(clientDirection, distance);
AddVectors(clientEyePosition, clientDirection, targetDestination);
Expand All @@ -23,6 +23,19 @@ void Math_CalculateThrowDirection(int client, float speed, float direction[VECTO
ScaleVector(direction, speed);
}

void Math_CalculatePlayerMiddle(int client, float middle[VECTOR_SIZE]) {
float origin[VECTOR_SIZE];
float minBounds[VECTOR_SIZE];
float maxBounds[VECTOR_SIZE];

GetClientAbsOrigin(client, origin);
GetClientMins(client, minBounds);
GetClientMaxs(client, maxBounds);
AddVectors(minBounds, maxBounds, middle);
ScaleVector(middle, HALF);
AddVectors(origin, middle, middle);
}

float Math_CalculateDistance(int client, int target) {
float clientPosition[VECTOR_SIZE];
float targetPosition[VECTOR_SIZE];
Expand All @@ -37,14 +50,14 @@ float Math_CalculateAngleToCone(int client, int target) {
float clientEyePosition[VECTOR_SIZE];
float clientEyeAngles[VECTOR_SIZE];
float clientDirection[VECTOR_SIZE];
float targetEyePosition[VECTOR_SIZE];
float targetPosition[VECTOR_SIZE];
float targetDirection[VECTOR_SIZE];

GetClientEyePosition(client, clientEyePosition);
GetClientEyeAngles(client, clientEyeAngles);
GetClientEyePosition(target, targetEyePosition);
Math_CalculatePlayerMiddle(target, targetPosition);
GetAngleVectors(clientEyeAngles, clientDirection, NULL_VECTOR, NULL_VECTOR);
SubtractVectors(targetEyePosition, clientEyePosition, targetDirection);
SubtractVectors(targetPosition, clientEyePosition, targetDirection);
NormalizeVector(targetDirection, targetDirection);

float dotProduct = GetVectorDotProduct(targetDirection, clientDirection);
Expand Down

0 comments on commit ec22cfc

Please sign in to comment.