helix snake 0 Posted August 29, 2015 Share Posted August 29, 2015 (edited) 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 map2: Intersect with mission entities? (includes train)4: Intersect with peds? (same as 8)8: Intersect with peds? (same as 4)10: vehicles16: Intersect with objects19: Unkown32: Unknown64: Unknown128: Unknown256: 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 August 29, 2015 by helix snake Link to post Share on other sites
leftas 125 Posted August 30, 2015 Share Posted August 30, 2015 (edited) I don't know where the author of that description took everything, but here is the official flags. 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 August 30, 2015 by leftas Link to post Share on other sites
whorse 26 Posted August 31, 2015 Share Posted August 31, 2015 (edited) 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 August 31, 2015 by whorse Link to post Share on other sites
GeorgeZhang 25 Posted August 31, 2015 Share Posted August 31, 2015 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 Link to post Share on other sites
whorse 26 Posted September 1, 2015 Share Posted September 1, 2015 (edited) 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 September 1, 2015 by whorse Link to post Share on other sites
whorse 26 Posted September 1, 2015 Share Posted September 1, 2015 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 Link to post Share on other sites
whorse 26 Posted September 4, 2015 Share Posted September 4, 2015 (edited) 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): 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: 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 September 5, 2015 by whorse 1 Link to post Share on other sites