Find the point on the ground where plane is heading to?
#1

How do i get the point on the ground (im using map andreas) where the plane that im flying is heading to?
Reply
#2

Nobody with any calculation really?^^
I have found this but I dont get it...
https://en.wikipedia.org/wiki/Line%E...e_intersection
Reply
#3

This?
from debug
Код HTML:
GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{	// Created by ******

	new Float:a;

	GetPlayerPos(playerid, x, y, a);
	GetPlayerFacingAngle(playerid, a);

	if (GetPlayerVehicleID(playerid)) {
	    GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
	}

	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}
and after this FindZ?
Reply
#4

I dont know the exact distance when Im flying around.

It would be like this:

URL: http://help.matheass.eu/de/Schnittvo...undGerade.html
The 2 red dots are 2 fixed points on my vehicle where the offset of one is shifted to the front.
So I got 2 points with 2 coords.
Then a nother point as the center of the sphere and the radius.
With this information it should possible to calcutate it
But i dont know how to calculate it...
Reply
#5

Hmm that's possible but what if plane changes its direction? then what will you do? because based on what you want it may take few seconds to take out that point and plane may change direction in a sec only
PS you can use this to get plane nose direction https://sampwiki.blast.hk/wiki/GetVehicleRotationQuat
Reply
#6

Doesn't matter if the calculation takes 3 seconds its also ok, the parameters are taken at the point where I start the calculation.

The point of that is that I want to calculate if I hit an vehicle with a rocket that is standing on the ground.
Because onplayershoot does not return a value from a seasparrow or a hydra.
So that would be the workaround
Reply
#7

Ok so I will tell you how its done
First have a look at this https://sampforum.blast.hk/showthread.php?tid=446462
Look at video and demo script in the video
Editing the above demo script we can achieve what you want..
So I edit somethings and made this (didn't tested it though) :
pawn Код:
#include <a_samp>
#include "VehicleMatrix.inc"

main(){}

stock IsAFlyingVehicle(vehicleid)
{
  switch(GetVehicleModel(vehicleid))
  {
    case
        460,464,476,511,512,513,519,520,553,577,592,593,//flying vehicle models
        417,425,447,465,469,487,488,497,501,548,563:
    return true;
  }
  return false;
}

stock GetPlaneHitPoint(playerid, &Float:hx, &Float:hy)
{
    if(!IsAFlyingVehicle(GetPlayerVehicleID(playerid)))return 0;
    new Float:pos[2][3];
    GetVehiclePos(GetPlayerVehicleID(playerid),pos[0][0],pos[0][1],pos[0][2]);
    PositionFromVehicleOffset(GetPlayerVehicleID(playerid),0.0,250.0,0.0,pos[1][0],pos[1][1],pos[1][2]);
    return checkpls(0,pos[0][0],pos[0][1],pos[0][2],pos[1][0],pos[1][1],pos[1][2], hx, hy);
}

stock checkpls(initiatore,Float:StartX,Float:StartY,Float:StartZ,Float:EndX,Float:EndY,Float:EndZ, &Float:hhx, &Float:hhy)
{
    new Float:AdderX = (EndX-StartX)/12.0;
    new Float:AdderY = (EndY-StartY)/12.0;
    new Float:AdderZ = (EndZ-StartZ)/12.0;
    new Float:sz;
    for(new i = 0, Float:x = 0.0; i < 12; ++i, x += 1.0)
    {
            MapAndreas_FindZ_For2DCoord(StartX+(AdderX*x),StartY+(AdderY*x), sz);
        if(sz >= StartZ+(AdderZ*x))
        {
                    hhx = StartX+(AdderX*x);
                        hhy = StartY+(AdderY*x);           
            return true;
        }
    }
    return false;
}
umm usage like this
pawn Код:
new Float:mx, Float:my;
if(GetPlaneHitPoint(playerid, mx, my))
{
//ok now ground hit points stored in mx and my use it for whatever you want
}
else
{
//plane is either too high or its nose direction is not pointing at ground
//or plane is not hitting the ground if it moves in same direction at range of 250.0
//or the vehicle in which player is not a plane
}
However this is not 100% accurate and also one prob that if till the result is get the target player may have moved to a new place
Reply
#8

Ty I will test it when i am at home, I saw that video some time ago but I cant find it^^
And there is no target player the target isnt moving so its more easy to handle
Reply
#9

Whats the "initiatore" in checkpls? Its never used...
Quote:
Originally Posted by BroZeus
Посмотреть сообщение
pawn Код:
stock checkpls(initiatore,Float:StartX,Float:StartY,Float:StartZ,Float:EndX,Float:EndY,Float:EndZ, &Float:hhx, &Float:hhy)
{
    new Float:AdderX = (EndX-StartX)/12.0;
    new Float:AdderY = (EndY-StartY)/12.0;
    new Float:AdderZ = (EndZ-StartZ)/12.0;
    new Float:sz;
    for(new i = 0, Float:x = 0.0; i < 12; ++i, x += 1.0)
    {
            MapAndreas_FindZ_For2DCoord(StartX+(AdderX*x),StartY+(AdderY*x), sz);
        if(sz >= StartZ+(AdderZ*x))
        {
                    hhx = StartX+(AdderX*x);
                        hhy = StartY+(AdderY*x);           
            return true;
        }
    }
    return false;
}
Reply
#10

Initiator is a word that means playerid in SA-MP. But indeed, it was never used so you can remove it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)