Author Topic: Trajectory bullet  (Read 1959 times)

0 Members and 1 Guest are viewing this topic.

Offline skrX

  • Soldier
  • **
  • Posts: 112
  • x ye.
Trajectory bullet
« on: February 12, 2016, 06:46:31 pm »
Hello everyone,

Once on the server, probably ExHunter, I saw something strange, the script by which you could see exactly where the bullet will hit, of course,
without the red line, I mean those little yellow dots on the map. Is there any way to do this?

« Last Edit: February 12, 2016, 08:10:47 pm by skrX »

Offline Home

  • Major(1)
  • Posts: 43
Re: trajectory bullet
« Reply #1 on: February 12, 2016, 07:58:06 pm »
Why would you want that?

Offline skrX

  • Soldier
  • **
  • Posts: 112
  • x ye.
Re: trajectory bullet
« Reply #2 on: February 12, 2016, 08:12:40 pm »
Why would you want that?

to own tests
« Last Edit: February 12, 2016, 08:14:22 pm by skrX »

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Trajectory bullet
« Reply #3 on: February 13, 2016, 05:49:05 am »
You can use this for now, in the future i'm planning to add TBullet.OnDestroy event.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Trajectory bullet
« Reply #4 on: February 13, 2016, 07:41:36 am »
Yeah, iterate through map bullets to detect new ones, and project them onto polygons using BallisticCast for example, then mark with WorldText.

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: Trajectory bullet
« Reply #5 on: February 14, 2016, 12:35:03 pm »
See here: https://www.youtube.com/watch?v=51MRXnBRdI0
I do not know just what I erroneously indicates lines do not show the bullet trajectory just perfect for the cursor.

Code: [Select]
unit BulletProjectiveLine;

const
Gravity = 0.06;

g_ = 0.135; //gravity acceleration [pixels/tick^2]
k_ = 0.01; // air resistance factor
ik_ = 1.0 - k_;

type
tTVector = record
x, y, vx, vy: single;
t: word;
end;

var
WeaponSpeed: array [0..16] of single;
Vec: tTVector;

function BallisticAim(x1, y1, x2, y2, v, gravity: single): single; external 'ballistic_aim@aim.dll';

function GetWeaponName(Weapon: Byte): String;
begin
case (Weapon) of
0: Result := 'USSOCOM';
1: Result := 'Desert Eagles';
2: Result := 'HK MP5';
3: Result := 'Ak-74';
4: Result := 'Steyr AUG';
5: Result := 'Spas-12';
6: Result := 'Ruger 77';
7: Result := 'M79';
8: Result := 'Barret M82A1';
9: Result := 'FN Minimi';
10: Result := 'XM214 Minigun';
11: Result:= 'Combat Knife';
12: Result:= 'Chainsaw';
13: Result:= 'M72 LAW';
14: Result:= 'Flamer';
15: Result:= 'Rambo Bow';
16: Result:= 'Flamed Arrows';
else Result := '';
end;
end;

procedure CastAndDraw(x, y, g: single; var vec: tTVector; CheckPlayerOnly, CheckBulletOnly: boolean);
var x2, y2: single;
begin
while vec.t > 0 do begin
vec.t := vec.t - 1;
x2 := x;
x := x + vec.vx;
vec.vx := vec.vx * ik_;
vec.vy := vec.vy + g;
y2 := y;
y := y + vec.vy;
vec.vy := vec.vy * ik_;
if Map.RayCast(x, y, x2, y2, CheckPlayerOnly, false, CheckBulletOnly, CheckBulletOnly, 0) then begin
vec.X := x2;
vec.Y := y2;
Players.WorldText(vec.t, '.', 60, $33CC00, 0.09, x-3, y-25);
exit;
end else
begin
Players.WorldText(vec.t, '.',60, $FF0000, 0.08, x-3, y-25);
end;
end;
vec.X := x2;
vec.Y := y2;
end;

procedure DrawBulletProjectiveLines(Player: TActivePlayer);
var Speed, Angle: single;
begin
if (Player.Primary.WType<>255) then begin
Speed := WeaponSpeed[Player.Primary.WType];

Angle := BallisticAim(Player.X, Player.Y, single(Player.MouseAimX), single(Player.MouseAimY), Speed, Gravity);

Vec.vx := (cos(angle)*Speed);
Vec.vy := (sin(angle)*Speed);
Vec.T := 400;
CastAndDraw(Player.X, Player.Y, g_*Gravity/Gravity, vec, true, true);
end;
end;

procedure Check(Ticks: integer);
var i:byte;
begin
for i := 1 to 32 do if (Players[i].Active) then if ((Players[i].Alive) and (Players[i].IsAdmin)) then DrawBulletProjectiveLines(Players[i]);
Players[1].WorldText(401, 'O', 60, $DCB2010, 0.10, single(Players[1].MouseAimX)-8, single(Players[1].MouseAimY)-23);
end;

procedure ReadWeaponsSpeed();
var i: byte; WeaponINI: TIniFile;
begin
if (Game.Realistic) then WeaponINI := File.CreateINI('weapons.ini') else WeaponINI := File.CreateINI('weapons_realistic.ini');
for i := 0 to 16 do WeaponSpeed[i] := (WeaponINI.ReadInteger(GetWeaponName(i), 'Speed', 0)/10);
end;

begin
ReadWeaponsSpeed();
Game.TickThreshold := 1;
Game.OnClockTick := @Check;
end.

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Trajectory bullet
« Reply #6 on: February 14, 2016, 04:08:17 pm »
try replacing

Code: [Select]
Angle := BallisticAim(Player.X, Player.Y, single(Player.MouseAimX), single(Player.MouseAimY), Speed, Gravity);

with
Code: [Select]
Angle := arctan2(Player.X - single(Player.MouseAimX), Player.Y - single(Player.MouseAimY));

or

Code: [Select]
Angle := arctan2(-Player.X + single(Player.MouseAimX), -Player.Y + single(Player.MouseAimY));