Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Happy Holidays from the GTANet team!

Help with code for some area


jstq
 Share

Recommended Posts

user posted image

black 1 is player's car

red 2 is player's car direction

green 3 is camera direction

gray 4 is on screen area, expanding to left

and red 5 is not on screen area

I need code which will return true for any car in area 5. Method isOnScreen often returns true for not on screen cars, so its bad for me.

And some question - how much foots is screen width while player is in car/not in car for 1920 pixels?

How to get foots count for maximum view distance?

Whats the fastest way to know, is really car displayed on screen or not? (isOnScreen will return true if between car and player is a building or wall).

Link to comment
Share on other sites

sextitsboobsyeah

user posted image

 

if u disregard the z value from a vector3 point, u can calculate this line with the car's position being the focus at a 0, 0 coordiante then u check car's relationship to the line, disregard what it says about sunlight i just went to google images for parabula and fount that and it looked like your picture

 

u know vector math?

Edited by sextitsboobsyeah
Link to comment
Share on other sites

no im noob in math :<

ill try to figure out some code in hope for some good method, maybe someone already did that b4.

vector3.z its height?

Link to comment
Share on other sites

sextitsboobsyeah

what i posted isnt hard if u read a little and u will learn something useful, think of the car being at 0, 0 on that graph and the focus point would be 0, 0... by getting a car's offset position u can use the offset value as the values u process with the formula... maybe if i get bored ill write it for u

 

a = distance from car to camera

then just plug in x values and u get your y values from formula

 

then those x and y's u use getoffsetposition and u can draw that line, then u check other cars distance to any point on the line

Edited by sextitsboobsyeah
Link to comment
Share on other sites

for me car position is at focus point...

sorry my natural language isnt english, so i misunderstand your words a little (like when i ask bout z value - i didnt know what word disregard means, i thought that you use Z value in calculations, but then i googled its value biggrin.gif )

Link to comment
Share on other sites

sextitsboobsyeah

lol... i will draw a picture and try to explain that way... one moment, what language u speak?

 

give me few minutes i have to google stuff, i dont use this type of math normally wink.gif

 

i will draw a nice picture with some code to explain wink.gif

Edited by sextitsboobsyeah
Link to comment
Share on other sites

and actually i didnt understand what offset is. this method is in vehicle class, not in position, and returns some world coordinates for some vector. but how that coordinates calculated, what are they means? some position in some vector3 direction from come car position?

user posted image

my language is russian suicidal.gif

Edited by jstq
Link to comment
Share on other sites

sextitsboobsyeah

ah ok, i know some spanish, nm lol

 

take this example:

 

vehicle.Position == vehicle.GetOffsetPosition(new Vector3(0, 0, 0)) is true

 

so a point in front of car or behind u change y value

 

vehicle.GetOffsetPosition(new Vector3(0, 5, 0)) is about 5 meters in front of car

 

so a point to left or right u change x value

 

vehicle.GetOffsetPosition(new Vector3(5, 0, 0)) is about 5 meters to right

 

and to get a point behind and to the left

 

vehicle.GetOffsetPosition(new Vector3(-5, -5, 0))

 

vehicle.GetOffsetPosition(new Vector3(left/right, front/back, up/down))

 

now because u are using offset positions and not world positions, u can create your picture using a horizontal parabola formula, i dont use normally but i understand how these things work so i am studying a little and i will make a picture to explain

 

in your picture i would say the point for that offset is something like... vehicle.GetOffsetPosition(new Vector3(7.5, 2.6, 0)), something like that, just a guess but u can use algebra to calculate any point relative to your focus point... being the car

 

this is cool, i just found...

 

http://www.wolframalpha.com/input/?i=plot+...-+3%29^2+%3D+11

Edited by sextitsboobsyeah
Link to comment
Share on other sites

but what if i need offset in direction where player looks (camera direction)?

user posted image

is that correct?

Player.Vehicle.GetOffsetPosition(Player.Direction*150);//150 or whatever range of view this is

and player.position is verctor from zero point to player position?

Link to comment
Share on other sites

sextitsboobsyeah

 

Player.Vehicle.GetOffsetPosition(Player.Position + Player.Direction*150);

fixed, also i dont understand what u mean for this, u need to study vector math to understand how to calculate stuff with vectors, this is cool though i like to learn this stuff and now im reading about parabolas lol

 

ill try to post an example tomorrow

Edited by sextitsboobsyeah
Link to comment
Share on other sites

i just dint get why that offset function is in vehicle class. If we have player position and some vector, we do not need any vehicle to calculate offset position imo. Or we need, cus that function is in vehicle class? biggrin.gif In other way, what this function takes from vehicle exemplar to calculate offset? If it gets vehicle position, why we need player.position?

Link to comment
Share on other sites

sextitsboobsyeah

 

i just dint get why that offset function is in vehicle class. If we have player position and some vector, we do not need any vehicle to calculate offset position imo. Or we need, cus that function is in vehicle class? biggrin.gif In other way, what this function takes from vehicle exemplar to calculate offset? If it gets vehicle position, why we need player.position?

it uses a native function to get the offset of a vehicle, it is what r* created, not sure why they didnt make one to get offsets from peds

 

this is what the code inside that method is:

 

<Module>.Scripting.?A0x8c04474b.GetOffsetFromCarInWorldCoords(this.pHandle, Offset.X, Offset.Y, Offset.Z, &x, &y, &z);

 

GetOffsetFromCarInWorldCoords was created by rockstar so u can see the method is specific to cars only, so it couldnt be applied to a ped unless u do some reversing and make the method think a ped is a car... that's another story, im sure it is possible though... maybe there is an offset for ped native??

 

also im not understanding your question but u use offset from car so u dont have to deal with world coordinates and the direction of your car will always be looking up on the y axis and the x axis will always be to the left and right of the car

 

what u need to do is use a horizontal parabola formula opening to the right and position it to the left of your car, think of your car on a x and y axis, the car is at 0, 0

 

Example:

 

user posted image

 

 

namespace Parabola{   using System;   using System.Drawing;   using System.Windows.Forms;   using System.Collections.Generic;   using GTA;   public class Main : Script   {       Blip[] blips;       public Main()       {           BindKey(Keys.B, Draw);           blips = new Blip[61];       }       private void Draw()       {           foreach (Blip blip in blips) if (Game.Exists(blip)) blip.Delete();           if (!Game.LocalPlayer.Character.isInVehicle()) return;           for (float y = -30; y < 31; y++) blips[(int)y + 30] = Blip.AddBlip(Game.LocalPlayer.Character.CurrentVehicle.GetOffsetPosition(new Vector3(xVal(y, -5, 0, 5), y, 0)));           foreach (Blip blip in blips) if (Game.Exists(blip)) blip.Scale = 0.5f;       }       private float xVal(float y, float h, float k, float a)       {           float x = 0;           x = 1 / (4 * a) * ((y - k) * (y - k)) + h;           return x;       }   }}

 

 

last thing u must do is determine if another car is inside or outside this parabola, the shape of the parabola can be modified by messing with the "a" value, eventually u will position the camera at the vertex and the car will be the focus point at (0, 0)... here i made vertex at (-5, 0) so a = 5 since that is how far vertex is from focus so u would do someting like... camera.Position = vehicle.GetOffsetPosition(new Vetcor3(-5, 0, 0))

Edited by sextitsboobsyeah
Link to comment
Share on other sites

sad.gif this parabola position is related only by car position, not by camera position sad.gif

GTA.Game.CurrentCamera.Direction - this is camera direction, now i need to learn some vector math and maybe ill figure out something

Edited by jstq
Link to comment
Share on other sites

blowjobcumpussy

but the camera's position is relative to the car so the parabola is also relative to the camera

 

btw valid a values when camera is positioned at vertex would be:

 

a = Game.CurrentCamera.Position.DistanceTo2D(vehicle.Position);

 

wink.gif

Edited by blowjobcumpussy
Link to comment
Share on other sites

blowjobcumpussy

 

Player.Position + Player.Direction*150;

 

what i wrote before i dont think was correct im just noticing, i fixed it now in quote to what i think u meant to write earlier

 

this is how it works, u start at your player, now your direction represents a length of 1 in the game so it's distance is 1f in the world... understand?

 

so if u have this direction and make it's range 150 times bigger, you can use that value to travel from any point 150f in the direction player is looking wink.gif

 

Direction Example:

let's say u need a direction from ped to another ped

 

Vector3.Normalize method takes a vector3 value and converts it into a length of 1... example:

 

Vector3.Normalize(Player.Character.Direction * 150) == Player.Character.Direction //this is true

 

 

this is how a Vector3's length is calculated:

 

(x^2 + y^2 + z^2)^0.5

 

or

 

 

float vector3Length = (float)Math.Sqrt((vector3.X * vector3.X) + (vector3.Y * vector3.Y) + (vector3.Z * vector3.Z));

 

 

I explain these because they are important and can help u to understand how to calculate directions or to get a direction from one object to another.

 

For directions from one object to another u simply subtract the position of the object, that the direction originates from, from the position of the object you are looking at. That vector3 value resulting from the subtraction tells u the direction but it is more that 1 unit long so u normalize it, this example below gives u direction from ped1 to ped2:

 

 

Vector3 directironFromPed1ToPed2 = Vector3.Normalize(ped2.Position - ped1.Position)

 

 

so normalizing the vector3 in this example is actually doing this:

 

 

Vecto3 vector3 = ped2.Position - ped1.Position;float normalizeMultiplier = 1 / vector3.Length();//see length code aboveVector3 directironFromPed1ToPed2 = new Vector3(vector3.X * normalizeMultiplier, vector3.Y * normalizeMultiplier, vector3.Z * normalizeMultiplier);

 

 

 

 

this will return true just to illustrate it

 

ped2.Position == Vector3.Normalize(ped2.Position - ped1.Position) * ped1.Position.DistanceTo(ped2.Position) + ped1.Position

 

 

so i think this what u were originally trying to write, hope that makes sense with google translate wink.gif

Edited by blowjobcumpussy
Link to comment
Share on other sites

  • 4 weeks later...

very nice math and all, but it still dosnt fix the problem of vehicles being "on screen" even if behind buildings...

 

i would run a (c++)

 

if(isCarOnScreen(thatcar) && inLineOfSight(mycar, thatcar)){do stuff}where inLineOfSight is something like:bool Inlineofsight(car1, car2){getcarcoods(car1, x,y,z);getcarcoods(car2, xx,yy,zz);Getgamecam(&gcam);getCamPosition(gcam, cx,cy,cz);f32 g=0;GetGroundZFor3DCoord(xx, yy, zz+1000,&g);while(g<=cz+20 && d>1){ //if ground position is lower than cam, there is no obstacle.getdistance3d(x,y,z,xx,yy,zz,&d);xx+=(x-xx)/d; //move check position closer to your caryy+=(y-yy)/d;zz+=(z-zz)/d;GetGroundZFor3DCoord(xx, yy, zz+1000,&g);}if(g>cz+20)return false;return true;}

 

 

sorry about the incredibly messy code, but im incredibly tired. smile.gif good luck understanding it, but i really believe it could work. good night (3am)

Link to comment
Share on other sites

hellothereyoupieceofshit

 

very nice math and all, but it still dosnt fix the problem of vehicles being "on screen" even if behind buildings...

 

i would run a (c++)

 

if(isCarOnScreen(thatcar) && inLineOfSight(mycar, thatcar)){do stuff}where inLineOfSight is something like:bool Inlineofsight(car1, car2){getcarcoods(car1, x,y,z);getcarcoods(car2, xx,yy,zz);Getgamecam(&gcam);getCamPosition(gcam, cx,cy,cz);f32 g=0;GetGroundZFor3DCoord(xx, yy, zz+1000,&g);while(g<=cz+20 && d>1){ //if ground position is lower than cam, there is no obstacle.getdistance3d(x,y,z,xx,yy,zz,&d);xx+=(x-xx)/d; //move check position closer to your caryy+=(y-yy)/d;zz+=(z-zz)/d;GetGroundZFor3DCoord(xx, yy, zz+1000,&g);}if(g>cz+20)return false;return true;}

 

 

sorry about the incredibly messy code, but im incredibly tired. smile.gif good luck understanding it, but i really believe it could work. good night (3am)

hi yes hello, welcome to jitsuin's forums, i hope you enjoy your stay...

 

it was only to provide ideas, i wasnt gonna write the thing lol

 

but thanks and yes i am the same person

Edited by hellothereyoupieceofshit
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.