midspace / Space-Engineers-Admin-script-mod

Modding script for Space Engineers with dozens of Admin commands for creating game scenarios or supporting servers.
43 stars 13 forks source link

Replace RayCastBlocks calls #170

Open midspace opened 8 years ago

midspace commented 8 years ago

Update calls to RayCastBlocks to use MyAPIGateway.Physics.CastRay.

https://github.com/midspace/Space-Engineers-Admin-script-mod/blob/master/midspace%20admin%20helper/Data/Scripts/midspace.adminscripts/Support.cs#L105

  MyAPIGateway.Physics.CastRay(start, end, out info);
    var hitGrid = info?.HitEntity as IMyCubeGrid;
    return hitGrid?.GetCubeBlock(hitGrid.WorldToGridInteger(info.Position + headTransform.Forward * 0.01))?.FatBlock as IMyTerminalBlock;
Spcemarine commented 8 years ago

Is this faster than the previously used method or just API changes?

midspace commented 8 years ago

It should be faster, from what I've heard. What is in question is the accuracy. It really needs testing, in terms of range, variety of entities and entity edges.

midspace commented 6 years ago

I've been researching this CastRay, and it's not practical. The raycast occurs in the Havok engine, against all objects between the two points. And it only returns the closest object. It does not have the capability of filtering by object type. ie, ignore asteroids and floating objects to only return the closest ship. It also does not detect planets.

What we really need is access to: public static void CastRay(Vector3D from, Vector3D to, List<HitInfo> toList, int raycastFilterLayer = 0) As this returns a list of hit objects. This would allows us to filter the results.