PeterTheHacker Posted May 4, 2016 Share Posted May 4, 2016 Simple question (hopefully) simple solution. How do I make a raycast ignore a ped (or list of peds if possible) so it doesn't stop when it hits that ped? The World.RayCast ignoreEntity argument either doesn't work or I'm not using it correctly. Thanks Link to comment Share on other sites More sharing options...
mockba.the.borg Posted May 5, 2016 Share Posted May 5, 2016 Hi Peter, The two last parameters of _CAST_RAY_POINT_TO_POINT can be used for that. Parameter 8 is an entity ID that the ray will ignore while travelling. I use that to ignore the player when when the ray originates from itself. Just set it to the PED's ID and the ray should ignore it. However, if the ray is departing from the player you have a problem. In this case you need to play with the last parameter, it is a bitmap which decides what will and will not be hit by the ray. I use 7 on that field to hit peds, cars and objects (targetting system), but you can play with the values. Usage is on the dev-c.com website: 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: vehicles Now, if you need ot ignore just one specific ped, not all of them, then your only option would be to use the 8th parameter, however this creates an issue if the ray is originating from the player: If the ray originates from the player position, then it comes from inside its body. Once it leaves the body, if it hits the player's hands or arms, it will now detect the player. So for me this was a problem, as my target system often targeted myself when I was aiming and running. The solution for this case is to originate the ray not from the player's position but from n meters further, towards the destination. A code example is below: -------- Get the new point n units from p1 going towards p2 function game.MovePoint(p1, p2, n) local distance = natives.SYSTEM.VDIST(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z) if distance < n*2 then distance = n*2 end local newX = p1.x+((n/distance)*(p2.x-p1.x)) local newY = p1.y+((n/distance)*(p2.y-p1.y)) local newZ = p1.z+((n/distance)*(p2.z-p1.z)) return {x=newX, y=newY, z=newZ} end and this is what I use for ray casting: -- Get the aimed entity and aimed point via RayCast function game.GetRaycastTarget(distance, flags, entity) local p1 = natives.CAM.GET_GAMEPLAY_CAM_COORD() local p2 = game.GetCoordsInFrontOfCam(distance) local ray = natives.WORLDPROBE._CAST_RAY_POINT_TO_POINT(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, flags, entity, 7) local m_hit = CMemoryBlock(4) local m_endCoords = CMemoryBlock(24) local m_surfaceNormal = CMemoryBlock(24) local m_entityHit = CMemoryBlock(4) local enum = natives.WORLDPROBE._GET_RAYCAST_RESULT(ray, m_hit, m_endCoords, m_surfaceNormal, m_entityHit) local hit = m_hit:ReadDWORD32(0) == 1 local endCoords = nil local surfaceNormal = nil local entityHit = nil local ent = nil if hit then endCoords = {x=m_endCoords:ReadFloat(0), y=m_endCoords:ReadFloat(2), z=m_endCoords:ReadFloat(4)} entityHit = m_entityHit:ReadDWORD32(0) ent = Entity(entityHit) if ent:IsPed() then ent = Ped(entityHit) end if ent:IsVehicle() then ent = Vehicle(entityHit) end if ent:IsObject() then ent = Object(entityHit) end end m_hit:Release() m_endCoords:Release() m_surfaceNormal:Release() m_entityHit:Release() return ent, endCoords end hope it helps. Cheers, Mockba. Link to comment Share on other sites More sharing options...
PeterTheHacker Posted May 5, 2016 Author Share Posted May 5, 2016 Hi Peter, The two last parameters of _CAST_RAY_POINT_TO_POINT can be used for that. Parameter 8 is an entity ID that the ray will ignore while travelling. I use that to ignore the player when when the ray originates from itself. Just set it to the PED's ID and the ray should ignore it. However, if the ray is departing from the player you have a problem. In this case you need to play with the last parameter, it is a bitmap which decides what will and will not be hit by the ray. I use 7 on that field to hit peds, cars and objects (targetting system), but you can play with the values. Usage is on the dev-c.com website: 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 Now, if you need ot ignore just one specific ped, not all of them, then your only option would be to use the 8th parameter, however this creates an issue if the ray is originating from the player: If the ray originates from the player position, then it comes from inside its body. Once it leaves the body, if it hits the player's hands or arms, it will now detect the player. So for me this was a problem, as my target system often targeted myself when I was aiming and running. The solution for this case is to originate the ray not from the player's position but from n meters further, towards the destination. A code example is below: -------- Get the new point n units from p1 going towards p2 function game.MovePoint(p1, p2, n) local distance = natives.SYSTEM.VDIST(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z) if distance < n*2 then distance = n*2 end local newX = p1.x+((n/distance)*(p2.x-p1.x)) local newY = p1.y+((n/distance)*(p2.y-p1.y)) local newZ = p1.z+((n/distance)*(p2.z-p1.z)) return {x=newX, y=newY, z=newZ} end and this is what I use for ray casting: -- Get the aimed entity and aimed point via RayCast function game.GetRaycastTarget(distance, flags, entity) local p1 = natives.CAM.GET_GAMEPLAY_CAM_COORD() local p2 = game.GetCoordsInFrontOfCam(distance) local ray = natives.WORLDPROBE._CAST_RAY_POINT_TO_POINT(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, flags, entity, 7) local m_hit = CMemoryBlock(4) local m_endCoords = CMemoryBlock(24) local m_surfaceNormal = CMemoryBlock(24) local m_entityHit = CMemoryBlock(4) local enum = natives.WORLDPROBE._GET_RAYCAST_RESULT(ray, m_hit, m_endCoords, m_surfaceNormal, m_entityHit) local hit = m_hit:ReadDWORD32(0) == 1 local endCoords = nil local surfaceNormal = nil local entityHit = nil local ent = nil if hit then endCoords = {x=m_endCoords:ReadFloat(0), y=m_endCoords:ReadFloat(2), z=m_endCoords:ReadFloat(4)} entityHit = m_entityHit:ReadDWORD32(0) ent = Entity(entityHit) if ent:IsPed() then ent = Ped(entityHit) end if ent:IsVehicle() then ent = Vehicle(entityHit) end if ent:IsObject() then ent = Object(entityHit) end end m_hit:Release() m_endCoords:Release() m_surfaceNormal:Release() m_entityHit:Release() return ent, endCoords end hope it helps. Cheers, Mockba. Thanks so much man! You saved my mod. I credited you (check version history in description) https://de.gta5-mods.com/scripts/bulletcam mockba.the.borg 1 Link to comment Share on other sites More sharing options...
Guest Posted September 26, 2016 Share Posted September 26, 2016 (edited) Now, if you need ot ignore just one specific ped, not all of them, then your only option would be to use the 8th parameter, however this creates an issue if the ray is originating from the player: If the ray originates from the player position, then it comes from inside its body. Once it leaves the body, if it hits the player's hands or arms, it will now detect the player. You might find this interesting... This is a video from my own camera mod that uses a set of orbital probes to find clear lines of sight. The rays originate from the player but as you can see, never register the player as a collision object... even when the ray passes directly through an arm. It uses this line as the test: _rcResult = World.Raycast(PedTarget.Position, Position, _intersectOption, PedTarget); PedTarget being the ignore Ped option... which is the player. Green = Clear, Red = Blocked, Purple = Selected https://youtu.be/_08rCDBMJkU Edited September 26, 2016 by Guest Link to comment Share on other sites More sharing options...
mockba.the.borg Posted September 30, 2016 Share Posted September 30, 2016 It would be cool to know what is the native usage behind World.Raycast. Maybe it is already doing the extra logic I do to avoid detecting the player, who knows. Link to comment Share on other sites More sharing options...
Guest Posted October 1, 2016 Share Posted October 1, 2016 It would be cool to know what is the native usage behind World.Raycast. Maybe it is already doing the extra logic I do to avoid detecting the player, who knows. RaycastResult::RaycastResult(int handle) : _hitEntity(nullptr){ int hitsomething = 0, enthandle = 0; Native::OutputArgument ^hitCoords = gcnew Native::OutputArgument(), ^surfaceNormal = gcnew Native::OutputArgument(); _result = Native::Function::Call<int>(Native::Hash::_GET_RAYCAST_RESULT, handle, &hitsomething, hitCoords, surfaceNormal, &enthandle); _didHit = hitsomething != 0; _hitCoords = hitCoords->GetResult<Math::Vector3>(); _surfaceNormal = surfaceNormal->GetResult<Math::Vector3>(); if (Native::Function::Call<bool>(Native::Hash::DOES_ENTITY_EXIST, enthandle)) { switch (Native::Function::Call<int>(Native::Hash::GET_ENTITY_TYPE, enthandle)) { case 1: _hitEntity = gcnew Ped(enthandle); break; case 2: _hitEntity = gcnew Vehicle(enthandle); break; case 3: _hitEntity = gcnew Prop(enthandle); break; } }} Doesn't seem to do anything other than basic native calls. Link to comment Share on other sites More sharing options...
mockba.the.borg Posted October 3, 2016 Share Posted October 3, 2016 It seems to return a value only if the type of the detected entity is not the player. So the cast ray is indeed "detecting" the player when his arm is in front (or maybe when another player is in front, though we will never know), but it doesn't return a value in that case. Clever solution. Thanks for sharing. Link to comment Share on other sites More sharing options...
Guest Posted October 4, 2016 Share Posted October 4, 2016 (edited) No problem... I don't know C++ so you can probably understand that better than me. Just out of curiosity, does _GET_RAYCAST_RESULT still exist on this page for you? http://www.dev-c.com/nativedb/ Because when I try to search for it, it says it doesn't exist... which is very odd. I'm sure it did exist, so I don't know if anything has changed with this latest update that has screwed things up with the Natives and they're having to redo some of it. I was just going to drop the native versions into my mod out of curiosity but with no info, I can't. Edit: _CAST_3D_RAY_POINT_TO_POINT seems to have gone as well. Edited October 4, 2016 by Guest Link to comment Share on other sites More sharing options...
unknown modder Posted October 4, 2016 Share Posted October 4, 2016 No problem... I don't know C++ so you can probably understand that better than me. Just out of curiosity, does _GET_RAYCAST_RESULT still exist on this page for you? http://www.dev-c.com/nativedb/ Because when I try to search for it, it says it doesn't exist... which is very odd. I'm sure it did exist, so I don't know if anything has changed with this latest update that has screwed things up with the Natives and they're having to redo some of it. I was just going to drop the native versions into my mod out of curiosity but with no info, I can't. Edit: _CAST_3D_RAY_POINT_TO_POINT seems to have gone as well. the actual names of most of WORLD_PROBE was figured out. Turns out R* internally calls them shape tests. get result is now GET_SHAPE_TEXT_RESULT, cast 3d... is now START_SHAPE_TEST_CAPSULE Link to comment Share on other sites More sharing options...
Guest Posted October 4, 2016 Share Posted October 4, 2016 (edited) No problem... I don't know C++ so you can probably understand that better than me. Just out of curiosity, does _GET_RAYCAST_RESULT still exist on this page for you? http://www.dev-c.com/nativedb/ Because when I try to search for it, it says it doesn't exist... which is very odd. I'm sure it did exist, so I don't know if anything has changed with this latest update that has screwed things up with the Natives and they're having to redo some of it. I was just going to drop the native versions into my mod out of curiosity but with no info, I can't. Edit: _CAST_3D_RAY_POINT_TO_POINT seems to have gone as well. the actual names of most of WORLD_PROBE was figured out. Turns out R* internally calls them shape tests. get result is now GET_SHAPE_TEXT_RESULT, cast 3d... is now START_SHAPE_TEST_CAPSULE So is this going to impact any existing mods? Especially in light of today's updates. My camera mod relies on raycasting extensively (using SHVDN) and having just shut development down on it, I'd rather be prepared for a whole host of "It's not working" reports if possible. Edited October 4, 2016 by Guest Link to comment Share on other sites More sharing options...
unknown modder Posted October 5, 2016 Share Posted October 5, 2016 No problem... I don't know C++ so you can probably understand that better than me. Just out of curiosity, does _GET_RAYCAST_RESULT still exist on this page for you? http://www.dev-c.com/nativedb/ Because when I try to search for it, it says it doesn't exist... which is very odd. I'm sure it did exist, so I don't know if anything has changed with this latest update that has screwed things up with the Natives and they're having to redo some of it. I was just going to drop the native versions into my mod out of curiosity but with no info, I can't. Edit: _CAST_3D_RAY_POINT_TO_POINT seems to have gone as well. the actual names of most of WORLD_PROBE was figured out. Turns out R* internally calls them shape tests. get result is now GET_SHAPE_TEXT_RESULT, cast 3d... is now START_SHAPE_TEST_CAPSULE So is this going to impact any existing mods? Especially in light of today's updates. My camera mod relies on raycasting extensively (using SHVDN) and having just shut development down on it, I'd rather be prepared for a whole host of "It's not working" reports if possible. no, it wont affect existing mods due to the 2.9.2 version of SHVDN still uses the hold hashes, and the new version (3.0) will be compatible to run alongside the old version Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now