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

Ignore Player From Raycast


PeterTheHacker
 Share

Recommended Posts

PeterTheHacker

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

mockba.the.borg

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.

 

Link to comment
Share on other sites

PeterTheHacker

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

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

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 by Guest
Link to comment
Share on other sites

mockba.the.borg

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

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

mockba.the.borg

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

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 by Guest
Link to comment
Share on other sites

unknown modder

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

 

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 by Guest
Link to comment
Share on other sites

unknown modder

 

 

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

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.