Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Cayo Perico Heist
      2. The Diamond Casino Heist
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

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

    1. Red Dead Redemption 2

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

    1. Grand Theft Auto Series

    2. GTA VI

      1. St. Andrews Cathedral
    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. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. 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. 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
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

Sign in to follow this  
helix snake

Getting vehicles with raycasting

Recommended Posts

helix snake

There's a "flags" variable that is supposed to be an intersection bitwise integer. The native DB at dev-c says that setting it to -1 will intersect with anything. Problem is, it doesn't: it doesn't intersect with vehicles.

 

So dev-c has this to say about the flags:

 

"Flags are intersection bit flags. They tell the ray what to care about and what not to care about when casting. Passing -1 will intersect with everything, presumably.

Flags:
1: Intersect with map
2: Intersect with mission entities? (includes train)
4: Intersect with peds? (same as 8)
8: Intersect with peds? (same as 4)
10: vehicles
16: Intersect with objects
19: Unkown
32: Unknown
64: Unknown
128: Unknown
256: Intersect with vegetation (plants, coral. trees not included)
512: Unknown"

 

Alright, now anyone versed in programming can tell you the problem here: there are numbers here that aren't powers of two. Specifically, vehicles is said to be assigned to "10". This doesn't make any sense. How do I make the raycasting interact with vehicles? I can't add vehicles to the bitwise intersection because it's 10 and that doesn't make any sense. That would be the same as adding 8 and 2. I'll mess around with this some more but I'd like help if someone else has done this. Setting it to 1023 (which should theoretically include all flags) doesn't work, as it still ignores vehicles.

 

After some testing, 0 doesn't work on anything, and 1023 doesn't work on vehicles, but 10 DOES work on vehicles (and only vehicles). so vehicles apparently aren't a flag, and whoever programmed the ray casting function was just on all sorts of drugs. The only way to check for EVERYTHING is to check for vehicles using 10, then check for everything else using -1, and then use whichever result has the shortest distance.

Edited by helix snake

Share this post


Link to post
Share on other sites
leftas

I don't know where the author of that description took everything, but here is the official flags.

 

dap09XE.png

 

And to mention bits flags are always power of two, so ten as decimal is really two flags, not one.

 

btw. if you set eighth flag, it gonna track everything, I guess.

 

All the best,

Paul.

Edited by leftas

Share this post


Link to post
Share on other sites
whorse

I am able to get vehicles, peds and objects all with the "-1" flag. I don't know why it isn't working for you.

I am making a gravity gun mod in C++ using raycasting and I have managed to get it to pick up objects, vehicles and pedestrians that I look/aim at. It uses the following (sample) code to detect targets:

BOOL hit; Vector3 endCoords; Vector3 surfaceNormal; Entity entityHandle = 0;while(true){    Vector3 camCoords = CAM::GET_GAMEPLAY_CAM_COORD();    Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(2);    Vector3 farCoords;        farCoords.x = camCoords.x + rotToDir(rot).x * 1000;        farCoords.y = camCoords.y + rotToDir(rot).y * 1000;        farCoords.z = camCoords.z + rotToDir(rot).z * 1000;    int ray = WORLDPROBE::_CAST_RAY_POINT_TO_POINT(camCoords.x, camCoords.y, camCoords.z, farCoords.x, farCoords.y, farCoords.z, -1, 0, 7);    WORLDPROBE::_GET_RAYCAST_RESULT(ray, &hit, &endCoords, &surfaceNormal, &entityHandle);    if (hit && (ENTITY::DOES_ENTITY_EXIST(entityHandle)))    {        if (ENTITY::IS_ENTITY_A_VEHICLE(entityHandle))              set_status_text("veh");         else if (ENTITY::IS_ENTITY_A_PED(entityHandle))              set_status_text("ped");         else if (ENTITY::IS_ENTITY_AN_OBJECT(entityHandle))              set_status_text("obj");    }    update_status_text();    WAIT(0);}   

rotToDir() is a function to get camera direction from its rotation, pretty much the same as what has already been posted in the other ray-casting threads.

 

How long are these rays supposed to go on for?. Mine is very accurate up to a certain distance, where if just stops working completely. Is it something I am doing wrong in the calculation of my farCoords variable? I admittedly suck at math and I copied the formulas from the internet. I thought the rays had infinite range before.

Edited by whorse

Share this post


Link to post
Share on other sites
GeorgeZhang

I am able to get vehicles, peds and objects all with the "-1" flag. I don't know why it isn't working for you.

I am making a gravity gun mod in C++ using raycasting and I have managed to get it to pick up objects, vehicles and pedestrians that I look/aim at. It uses the following (sample) code to detect targets:

 

BOOL hit; Vector3 endCoords; Vector3 surfaceNormal; Entity entityHandle = 0;while(true){    Vector3 camCoords = CAM::GET_GAMEPLAY_CAM_COORD();    Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(2);    Vector3 farCoords;        farCoords.x = camCoords.x + rotToDir(rot).x * 1000;        farCoords.y = camCoords.y + rotToDir(rot).y * 1000;        farCoords.z = camCoords.z + rotToDir(rot).z * 1000;    int ray = WORLDPROBE::_CAST_RAY_POINT_TO_POINT(camCoords.x, camCoords.y, camCoords.z, farCoords.x, farCoords.y, farCoords.z, -1, 0, 7);    WORLDPROBE::_GET_RAYCAST_RESULT(ray, &hit, &endCoords, &surfaceNormal, &entityHandle);    if (hit && (ENTITY::DOES_ENTITY_EXIST(entityHandle)))    {        if (ENTITY::IS_ENTITY_A_VEHICLE(entityHandle))              set_status_text("veh");         else if (ENTITY::IS_ENTITY_A_PED(entityHandle))              set_status_text("ped");         else if (ENTITY::IS_ENTITY_AN_OBJECT(entityHandle))              set_status_text("obj");    }    update_status_text();    WAIT(0);}   
rotToDir() is a function to get camera direction from its rotation, pretty much the same as what has already been posted in the other ray-casting threads.

 

How long are these rays supposed to go on for?. Mine is very accurate up to a certain distance, where if just stops working completely. Is it something I am doing wrong in the calculation of my farCoords variable? I admittedly suck at math and I copied the formulas from the internet. I thought the rays had infinite range before.

I think it just get results between source to target now, so maybe you should extend your farcoords vector by changing * 1000 to *3000 or * 5000. I was able to add an explosion on Maze Bank with raycast from Vinewood hills:D

Share this post


Link to post
Share on other sites
whorse

 

I am able to get vehicles, peds and objects all with the "-1" flag. I don't know why it isn't working for you.

I am making a gravity gun mod in C++ using raycasting and I have managed to get it to pick up objects, vehicles and pedestrians that I look/aim at. It uses the following (sample) code to detect targets:

BOOL hit; Vector3 endCoords; Vector3 surfaceNormal; Entity entityHandle = 0;while(true){    Vector3 camCoords = CAM::GET_GAMEPLAY_CAM_COORD();    Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(2);    Vector3 farCoords;        farCoords.x = camCoords.x + rotToDir(rot).x * 1000;        farCoords.y = camCoords.y + rotToDir(rot).y * 1000;        farCoords.z = camCoords.z + rotToDir(rot).z * 1000;   int ray = WORLDPROBE::_CAST_RAY_POINT_TO_POINT(camCoords.x, camCoords.y, camCoords.z, farCoords.x, farCoords.y, farCoords.z, -1, 0, 7);   WORLDPROBE::_GET_RAYCAST_RESULT(ray, &hit, &endCoords, &surfaceNormal, &entityHandle);   if (hit && (ENTITY::DOES_ENTITY_EXIST(entityHandle)))   {        if (ENTITY::IS_ENTITY_A_VEHICLE(entityHandle))                set_status_text("veh");        else if (ENTITY::IS_ENTITY_A_PED(entityHandle))                set_status_text("ped");        else if (ENTITY::IS_ENTITY_AN_OBJECT(entityHandle))                set_status_text("obj");    }    update_status_text();    WAIT(0);}
rotToDir() is a function to get camera direction from its rotation, pretty much the same as what has already been posted in the other ray-casting threads.

 

How long are these rays supposed to go on for?. Mine is very accurate up to a certain distance, where if just stops working completely. Is it something I am doing wrong in the calculation of my farCoords variable? I admittedly suck at math and I copied the formulas from the internet. I thought the rays had infinite range before.

I think it just get results between source to target now, so maybe you should extend your farcoords vector by changing * 1000 to *3000 or * 5000. I was able to add an explosion on Maze Bank with raycast from Vinewood hills:D

 

 

 

 

I tried setting it to 5000 and 10000 before and for some reason it makes no difference to the range. When I aim at an object like a park bench, sometimes the range only seems like ~30 distance units too, while I can get cars and peds from a little bit further away. I use the same formula for getting the in-air coords of the place I want to hold the grav_gun_entity, and it works great for that:

Vector3 holdCoords;    holdCoords.x = camPos.x + rotToDir(rot).x * 15;    holdCoords.y = camPos.y + rotToDir(rot).y * 15;    holdCoords.z = camPos.z + rotToDir(rot).z * 15;
Edited by whorse

Share this post


Link to post
Share on other sites
whorse

Nevermind, I'm pretty sure I couldnt grab the further entities because I was not waiting long enough for REQUEST_CONTROL_OF_ENTITY to get control. Now I can grab peds and props from very long range. However, like 2/3 of all (very) distant cars will still not react to the gravity gun, especially those sitting at stoplights, but car wrecks and props at the same distance always will.. oh well

Share this post


Link to post
Share on other sites
whorse

ACTUALLY, now that I look closer, it seems that the ped needs to be in the game's active "script pool" of entities (peds you've had interactions with, cars you've dented, and peds/vehicles called with natives like the "PED::GET_PED_NEARBY_VEHICLES/PEDS functions... entities that don't disappear as easily) The ray-casting is working perfectly and is returning the ped handle, but the ped was not responding to natives that commanded them to do things because they were not in the main pool. I tried using GET NEARBY VEHICLES on target vehicles that were very far away (instead of on "player"), and I am finally able to grab them 100% of the time now. To be safe, I do assign the nearby-peds/vehicles results to an array (there can only be 16 returned at a time I'm pretty sure), and I immediately iterate through them to mark them all as "NO LONGER NEEDED", but by doing so I finally add the distant ped/vehicle to the active "pool" and make them able to respond to commands by the script.

 

EDIT: More on PED::GET_PED_NEARBY_PEDS and PED::GET_PED_NEARBY_VEHICLES

 

 

I just tried having my script draw a line between the target's coordinates and all the nearby ped's coordinates attained off that target, and it turns out that no valid nearby peds are received unless the native is applied to the player. No lines are drawn unless I target myself as the gravity gun target. I'd seen that the number of peds returned by the native was not always zero, so I thought it was actually working for the nearby peds around the target, but I guess not. Here is what it looks like when I draw a line between the player and all the nearby peds around the player, though (peds are all on the bridge above):

OhSyPNn.jpg

 

EDIT2: I was wrong up above, the native does return the peds/vehicles nearby whatever entity you call it on - it is not limited to only the player. Here is what it looks like when I use GET_NEARBY_PEDS on a distant target and have lines drawn between that target and all the peds returned by the native:

kNWIYX7.jpg

 

I can swing the target around so he is way out over the other way down the road, and all the peds sending lines to him will change with where I move him. Right now I'm trying to find out if all the peds with lines on them are added to the "active-pool" by the native, or if they can only be reported as "nearby" if they were already in that pool to begin with.

Sorry for going a little off topic, I just thought this was interesting.

 

 

EDIT 3: Okay, so NETWORK::REQUEST_CONTROL_OF_ENTITY() is indeed crucially important (even in single player) for using natives on distant entities. I found that a vehicle cannot be successfully used as the source for "GET_PED_NEARBY_PEDS" or "GET_PED_NEARBY_VEHICLES". However, the handle of a ped inside a vehicle can be used to get nearby peds, but they will not be able to return nearby vehicles unless they are on foot

 

 

Edited by whorse
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 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.