Quantcast

Jump to content

» «
Photo

[Raycast] What the function START_SHAPE_TEST_CAPSULE does?

7 replies to this topic
Aktarus
  • Aktarus

    Player Hater

  • Members
  • Joined: 21 Aug 2017
  • United-Kingdom

#1

Posted 4 weeks ago Edited by Aktarus, 4 weeks ago.

Hi guys. I am triyng to understand how Raycast works. My objective is to scan around a ped (like a sonar) until find another ped. It seems that Raycast is a solution for my case. But what START_SHAPE_TEST_CAPSULE does exactly?

Is it only a straight line? Here is the doc from dev-c.com/nativedb/func :

 

 

WORLDPROBE::START_SHAPE_TEST_CAPSULE

 

Hashes: 0x28579D1B8F8AAC80 0x591EA833

int START_SHAPE_TEST_CAPSULE(float x1, float y1, float z1, float x2, float y2, float z2, float radius, int flags, 
Entity entity, int p9) // 0x28579D1B8F8AAC80 0x591EA833

Raycast from point to point, where the ray has a radius.

flags:
vehicles=10
peds =12

Iterating through flags yields many ped / vehicle/ object combinations

p9 = 7, but no idea what it does

Entity is an entity to ignore


sollaholla
  • sollaholla

    C# Dev.

  • Members
  • Joined: 19 May 2016
  • United-States

#2

Posted 4 weeks ago Edited by sollaholla, 4 weeks ago.

START_SHAPE_TEST_CAPSULE is what you'd expect; it's a capsule. It can also be a sphere as well.
What language are you going to be using? .NET has a very simplified function for this.


Aktarus
  • Aktarus

    Player Hater

  • Members
  • Joined: 21 Aug 2017
  • United-Kingdom

#3

Posted 4 weeks ago

START_SHAPE_TEST_CAPSULE is what you'd expect; it's a capsule. It can also be a sphere as well.
What language are you going to be using? .NET has a very simplified function for this.

 

Hi, I am using C#. Could you tell me what is the simplified function?

Thank you


sollaholla
  • sollaholla

    C# Dev.

  • Members
  • Joined: 19 May 2016
  • United-States

#4

Posted 4 weeks ago Edited by sollaholla, 4 weeks ago.

 

START_SHAPE_TEST_CAPSULE is what you'd expect; it's a capsule. It can also be a sphere as well.
What language are you going to be using? .NET has a very simplified function for this.

 

Hi, I am using C#. Could you tell me what is the simplified function?

Thank you

 

Yes, of course. Use this method and it should be much easier for you:

public static RaycastResult Raycast(Vector3 source, Vector3 direction, float maxDistance, IntersectOptions options, Entity ignoreEntity = null)

In the RaycastResult struct, there are many parameters that hold information about what the ray hit, it's hit location, etc.

There's also this function, since you where asking about capsule casting: 

public static RaycastResult RaycastCapsule(Vector3 source, Vector3 target, float radius, IntersectOptions options, Entity ignoreEntity = null)

All of these can be found in the World class.

Hope this helps, cheers.

  • Ezio Baggins and Aktarus like this

Aktarus
  • Aktarus

    Player Hater

  • Members
  • Joined: 21 Aug 2017
  • United-Kingdom

#5

Posted 4 weeks ago

Wow! Sure it helps Sollaholla.

I am going to try.

 

Thanks again

  • sollaholla likes this

Aktarus
  • Aktarus

    Player Hater

  • Members
  • Joined: 21 Aug 2017
  • United-Kingdom

#6

Posted 4 weeks ago Edited by Aktarus, 4 weeks ago.

So the code below works partially, because it stops after few seconds. I have an error in the console that's say: "Object reference not set to an instance of an object".

public async Task OnTick()
{
   Vector3 Pos = Function.Call<Vector3>(Hash.GET_ENTITY_COORDS, pedOfOrigin);

   Vector3 newPositionTarget = new Vector3
    {
         X = Pos.X + 30f,
         Y = Pos.Y,
         Z = Pos.Z
     };

    RaycastResult RaycastPed = World.RaycastCapsule(pedOfOrigin.Position, newPositionTarget, 60f, IntersectOptions.Peds1, null);

    Ped foundPed = new Ped(RaycastPed.HitEntity.Handle);

    Vector3 foundPedPos = Function.Call<Vector3>(Hash.GET_ENTITY_COORDS, foundPed);

    pedOfOrigin.Task.RunTo(foundPed.Position, true);
}

Does anyone knows what that means?

Thanks in advance


sollaholla
  • sollaholla

    C# Dev.

  • Members
  • Joined: 19 May 2016
  • United-States

#7

Posted 4 weeks ago Edited by sollaholla, 4 weeks ago.

So the code below works partially, because it stops after few seconds. I have an error in the console that's say: "Object reference not set to an instance of an object".

public async Task OnTick()
{
   Vector3 Pos = Function.Call<Vector3>(Hash.GET_ENTITY_COORDS, pedOfOrigin);

   Vector3 newPositionTarget = new Vector3
    {
         X = Pos.X + 30f,
         Y = Pos.Y,
         Z = Pos.Z
     };

    RaycastResult RaycastPed = World.RaycastCapsule(pedOfOrigin.Position, newPositionTarget, 60f, IntersectOptions.Peds1, null);

    Ped foundPed = new Ped(RaycastPed.HitEntity.Handle);

    Vector3 foundPedPos = Function.Call<Vector3>(Hash.GET_ENTITY_COORDS, foundPed);

    pedOfOrigin.Task.RunTo(foundPed.Position, true);
}

Does anyone knows what that means?

Thanks in advance

I'm sure that it's because foundPed is returning null. Before getting the position of the ped you should check RaycastPed.DitHitEntity.

  • Aktarus likes this

Aktarus
  • Aktarus

    Player Hater

  • Members
  • Joined: 21 Aug 2017
  • United-Kingdom

#8

Posted 4 weeks ago

Thanks. Problem solved. :lol:

  • sollaholla likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users