Exemplo n.º 1
0
        public static bool CanSee(PedHandle ped, Vector3 pos, IntersectOptions opts = IntersectOptions.Map | IntersectOptions.Objects)
        {
            Vector3       start  = HeadPosition(ped);
            float         len    = (start - pos).Length();
            RaycastResult result = Raycast(start, pos, opts, ped);

            return(result.DidHit ? (start - result.HitPosition).Length() / len > .99f : false);
        }
Exemplo n.º 2
0
 public static RaycastResult Raycast(Vector3 source, Vector3 target, IntersectOptions options, Entity ignoreEntity = null)
 {
     InputArgument[] argumentArray1 = new InputArgument[9];
     argumentArray1[0] = source.X;
     argumentArray1[1] = source.Y;
     argumentArray1[2] = source.Z;
     argumentArray1[3] = target.X;
     argumentArray1[4] = target.Y;
     argumentArray1[5] = target.Z;
     argumentArray1[6] = options;
     argumentArray1[7] = (ignoreEntity == null) ? 0 : ignoreEntity.Handle;
     InputArgument[] arguments = argumentArray1;
     arguments[8] = 7;
     return(new RaycastResult(Function.Call <int>(Hash._START_SHAPE_TEST_RAY, arguments)));
 }
Exemplo n.º 3
0
        public static RaycastResult RaycastCapsule(Vector3 source, Vector3 direction, float maxDistance, float radius, IntersectOptions options, Entity ignoreEntity = null)
        {
            Vector3 vector = source + (direction * maxDistance);

            InputArgument[] argumentArray1 = new InputArgument[10];
            argumentArray1[0] = source.X;
            argumentArray1[1] = source.Y;
            argumentArray1[2] = source.Z;
            argumentArray1[3] = vector.X;
            argumentArray1[4] = vector.Y;
            argumentArray1[5] = vector.Z;
            argumentArray1[6] = radius;
            argumentArray1[7] = options;
            argumentArray1[8] = (ignoreEntity == null) ? 0 : ignoreEntity.Handle;
            InputArgument[] arguments = argumentArray1;
            arguments[9] = 7;
            return(new RaycastResult(Function.Call <int>(Hash.START_SHAPE_TEST_CAPSULE, arguments)));
        }
Exemplo n.º 4
0
        public static Vector3 RaycastHit(Vector3 source, Vector3 target, IntersectOptions options, float max_distance)
        {
            int t = Function.Call <int>(Hash._START_SHAPE_TEST_RAY, source.X, source.Y, source.Z,
                                        target.X, target.Y, target.Z, (int)options, 0, 7);

            var hitPos = new OutputArgument();
            var ditHit = new OutputArgument();
            var entity = new OutputArgument();
            var normal = new OutputArgument();

            int     result       = Function.Call <int>(Hash.GET_SHAPE_TEST_RESULT, t, ditHit, hitPos, normal, entity);
            Vector3 hit_position = hitPos.GetResult <Vector3>();

            if (source.DistanceTo(hit_position) > max_distance)
            {
                return(Vector3.Zero);
            }

            return(hit_position);
        }
Exemplo n.º 5
0
        public static ObstructionFlags CheckObstruction(Vector3 start, Vector3 heading, bool debug = false)
        {
            ObstructionFlags ret = ObstructionFlags.None;

            if (IsRagdoll(Self))                // Call<bool>(IS_PED_RAGDOLL, Self) ) {
            {
                return(ret);
            }
            heading = new Vector3(heading.X, heading.Y, 0f);
            IntersectOptions opts        = IntersectOptions.Map | IntersectOptions.Objects | IntersectOptions.Vehicles;
            float            capsuleSize = .12f;
            float            stepSize    = .25f;

            heading = Vector3.Normalize(heading) * .5f;
            Vector3 head = HeadPosition(Self) + (Up * 5 * stepSize);

            for (int i = 1; i <= (int)ObstructionFlags.Knee; i *= 2)             // do probes from top to bottom
            {
                RaycastResult headRay = Raycast(head, head + heading, capsuleSize, opts, Self);
                if (headRay.DidHit)
                {
                    if (debug)
                    {
                        DrawSphere(headRay.HitPosition, .01f, Color.Red);
                    }
                    ret |= (ObstructionFlags)i;
                }
                head.Z -= stepSize;
            }
            if (debug)
            {
                string str = IsWalkable(ret) ? "Walkable" : IsClimbable(ret) ? "Climbable" : "Blocked";
                UI.DrawTextInWorld(HeadPosition(Self) + heading, $"{str}");
            }
            return(ret);
        }
Exemplo n.º 6
0
		public static RaycastResult RaycastCapsule(Vector3 source, Vector3 direction, float maxDistance, float radius, IntersectOptions options, Entity ignoreEntity = null)
		{
			Vector3 target = source + direction * maxDistance;

			return new RaycastResult(Function.Call<int>(Hash.START_SHAPE_TEST_CAPSULE, source.X, source.Y, source.Z, target.X, target.Y, target.Z, radius, options, ignoreEntity == null ? 0 : ignoreEntity.Handle, 7));
		}
Exemplo n.º 7
0
		public static RaycastResult Raycast(Vector3 source, Vector3 target, IntersectOptions options, Entity ignoreEntity = null)
		{
			return new RaycastResult(Function.Call<int>(Hash._START_SHAPE_TEST_RAY, source.X, source.Y, source.Z, target.X, target.Y, target.Z, options, ignoreEntity == null ? 0 : ignoreEntity.Handle, 7));
		}
Exemplo n.º 8
0
 /// <summary>
 /// A partial CanSee(). eg NearbyHumans().Where(CanSee(Self, opts));
 /// </summary>
 public static Func <PedHandle, bool> CanSee(PedHandle self, IntersectOptions opts) => (PedHandle p) => CanSee(self, p, opts);
Exemplo n.º 9
0
 public static bool CanSee(PedHandle self, PedHandle ped, IntersectOptions opts = IntersectOptions.Map | IntersectOptions.Objects) => self == default || ped == default ? false : Call <bool>(HAS_ENTITY_CLEAR_LOS_TO_ENTITY, self, ped, opts);
Exemplo n.º 10
0
        public unsafe static ShapeTestResult RunShapeTest(Vector3 start, Vector3 end, Entity ignoreEntity, IntersectOptions options)
        {
            var shapeTest = Function.Call <int>(Hash._CAST_RAY_POINT_TO_POINT,
                                                start.X, start.Y, start.Z, end.X, end.Y, end.Z, (int)options, ignoreEntity, 7);

            bool didHit;

            int result, handle;

            float[] hitPosition = new float[6], hitNormal = new float[6];

            int material;

            fixed(float *position = hitPosition)
            fixed(float *normal = hitNormal)
            {
                result = Function.Call <int>((Hash)0x65287525D951F6BE, shapeTest, &didHit, position, normal, &material, &handle);
            }

            return(new ShapeTestResult(didHit, handle, new Vector3(hitPosition[0], hitPosition[2], hitPosition[4]),
                                       new Vector3(hitNormal[0], hitNormal[2], hitNormal[4]), (materials)material));
        }
Exemplo n.º 11
0
 public static RaycastResult RaycastCapsule(Vector3 source, Vector3 target, float radius, IntersectOptions options, Entity ignoreEntity = null)
 {
     return(new RaycastResult(Function.Call <int>(Hash._CAST_3D_RAY_POINT_TO_POINT, source.X, source.Y, source.Z, target.X, target.Y, target.Z, radius, options, ignoreEntity == null ? 0 : ignoreEntity.Handle, 7)));
 }
Exemplo n.º 12
0
        public static RaycastResult Raycast(Vector3 source, Vector3 direction, float maxDistance, IntersectOptions options, Entity ignoreEntity = null)
        {
            Vector3 target = source + direction * maxDistance;

            return(new RaycastResult(Function.Call <int>(Hash._CAST_RAY_POINT_TO_POINT, source.X, source.Y, source.Z, target.X, target.Y, target.Z, options, ignoreEntity == null ? 0 : ignoreEntity.Handle, 7)));
        }
Exemplo n.º 13
0
 public static RaycastResult Raycast(Vector3 source, Vector3 target, float radius, IntersectOptions options, int ignoreEntity) =>
 new RaycastResult(Call <int>(START_SHAPE_TEST_CAPSULE, source, target, radius, options, ignoreEntity, 7));
Exemplo n.º 14
0
 public static RaycastResult Raycast(Vector3 source, Vector3 target, IntersectOptions options, int ignoreEntity) =>
 new RaycastResult(Call <int>(_START_SHAPE_TEST_RAY, source, target, options, ignoreEntity, 7));
Exemplo n.º 15
0
 public static RaycastResult Raycast(Vector3 source, Vector3 target, float radius, IntersectOptions options, PedHandle ignoreEntity) => Raycast(source, target, radius, options, (int)ignoreEntity);