News: Welcome back to Bullworth! If you haven't already, you will need to reset your password..


Author Topic: How to get the area in front of a ped?  (Read 1096 times)

0 Members and 1 Guest are viewing this topic.

Offline Histeria Beagles

  • Jr. Member
  • **
  • Posts: 4
  • Gender: Male
    • View Profile
How to get the area in front of a ped?
« on: August 24, 2022, 10:51:27 AM »
I want to create a hitbox for an animation that doesn't have one, probably I would need to use PedIsPedInBox() or PedInRectangle(). However, depending on where the ped is facing, these functions will return an undesired area (behind the ped or sides).

So, how can I do that? how to detect a small area in front of a ped?

Offline SimonBestia

  • Full Member
  • ***
  • Posts: 293
  • Gender: Male
  • Bully-Board's Best Weeb
    • View Profile
    • Youtube Channel
Re: How to get the area in front of a ped?
« Reply #1 on: August 25, 2022, 02:10:27 AM »
Since you mentioned a hitbox for an animation, I can assume the ped will be facing another ped in front of them to fight in the ideal situation?
You could try using a combination of PedCanSeeObject() and DistanceBetweenPeds2D() (or 3D).

Offline Altamurenza

  • Full Member
  • ***
  • Posts: 118
  • Gender: Male
  • I love cheat, unique, realistic, & expansion mod.
    • View Profile
Re: How to get the area in front of a ped?
« Reply #2 on: August 25, 2022, 06:02:49 AM »
So, how can I do that? how to detect a small area in front of a ped?

You can use PedGetOffsetInWorldCoords function to do that.

The function has four arguments:
1. Ped (ex: gPlayer)
2. Left (> 0, greater than zero) or Right (< 0, lesser than zero)
3. Front (> 0, greater than zero) or Back (< 0, lesser than zero)
4. Up (> 0, greater than zero) or Down (< 0, lesser than zero)

It returns the desired position in coordinates (X, Y, Z).

Test the function by adding a yellow-ground-blip in front of the player:
Code: [Select]
if IsButtonBeingPressed(3, 0) then
  local FRONT_X, FRONT_Y, FRONT_Z = PedGetOffsetInWorldCoords(gPlayer, 0, 1, 0)
  if BLIP then BlipRemove(BLIP) end
  BLIP = BlipAddXYZ(FRONT_X, FRONT_Y, FRONT_Z, 0, 0, 7)
end

Offline Ming

  • Full Member
  • ***
  • Posts: 154
  • Gender: Male
  • 抽刀斷水水更流,舉杯消愁愁更愁
    • View Profile
Re: How to get the area in front of a ped?
« Reply #3 on: September 05, 2022, 04:03:14 AM »