Show / Hide Table of Contents

Interface IMyPhysics

Mod API interface giving you access to physics

Namespace: VRage.Game.ModAPI
Assembly: VRage.Game.dll
Syntax
public interface IMyPhysics

Properties

ServerSimulationRatio

The server's simulation ratio. When physics cannot keep up server side this is smaller than 1.

Declaration
float ServerSimulationRatio { get; }
Property Value
Type Description
System.Single

SimulationRatio

Simulation ratio, when physics cannot keep up, this is smaller than 1

Declaration
float SimulationRatio { get; }
Property Value
Type Description
System.Single

StepsLastSecond

Number of physics steps done in last second

Declaration
int StepsLastSecond { get; }
Property Value
Type Description
System.Int32

Methods

CalculateArtificialGravityAt(Vector3D, Single)

Returns current artificial gravity at world position.

Declaration
Vector3 CalculateArtificialGravityAt(Vector3D worldPosition, float naturalGravityInterference = 1F)
Parameters
Type Name Description
Vector3D worldPosition

Target position

System.Single naturalGravityInterference

Artificial gravity strength is affected by presence of natural gravity. Use CalculateNaturalGravityAt(Vector3D, out Single) to get correct value for given point in space. Value of 1 indicates no natural gravity effect.

Returns
Type Description
Vector3

CalculateNaturalGravityAt(Vector3D, out Single)

Returns current natural gravity at world position.

Declaration
Vector3 CalculateNaturalGravityAt(Vector3D worldPosition, out float naturalGravityInterference)
Parameters
Type Name Description
Vector3D worldPosition

Target position

System.Single naturalGravityInterference

Natural gravity affects artificial gravity strength. Use this value when calling CalculateArtificialGravityAt(Vector3D, Single) to get effective (physical) strength of artificial gravity at point.

Returns
Type Description
Vector3

CastLongRay(Vector3D, Vector3D, out IHitInfo, Boolean)

Finds closest or any object on the path of the ray from->to. Uses Storage for voxels for faster search but only good for long rays (more or less more than 50m). Use it only in such cases.

Declaration
bool CastLongRay(Vector3D from, Vector3D to, out IHitInfo hitInfo, bool any)
Parameters
Type Name Description
Vector3D from

Start of the ray.

Vector3D to

End of the ray.

IHitInfo hitInfo

Hit info

System.Boolean any

Indicates if method should return any object found (May not be closest)

Returns
Type Description
System.Boolean

true if hit, false if no hit

CastRay(Vector3D, Vector3D, List<IHitInfo>, Int32)

Cast a ray and returns all matching entities. Must not be called from parallel thread!!!

Declaration
void CastRay(Vector3D from, Vector3D to, List<IHitInfo> toList, int raycastFilterLayer = 0)
Parameters
Type Name Description
Vector3D from

Start of ray.

Vector3D to

End of ray.

System.Collections.Generic.List<IHitInfo> toList

List of hits

System.Int32 raycastFilterLayer

Collision layer

CastRay(Vector3D, Vector3D, out IHitInfo, Int32)

Cast a ray and return first entity. Must not be called from parallel thread!!!

Declaration
bool CastRay(Vector3D from, Vector3D to, out IHitInfo hitInfo, int raycastFilterLayer = 0)
Parameters
Type Name Description
Vector3D from

Start of ray.

Vector3D to

End of ray.

IHitInfo hitInfo

Hit info

System.Int32 raycastFilterLayer

Collision layer

Returns
Type Description
System.Boolean

true if hit; false if no hit

CastRay(Vector3D, Vector3D, out IHitInfo, UInt32, Boolean)

Cast a ray and return first entity. Must not be called from parallel thread!!!

Declaration
bool CastRay(Vector3D from, Vector3D to, out IHitInfo hitInfo, uint raycastCollisionFilter, bool ignoreConvexShape)
Parameters
Type Name Description
Vector3D from

Start of ray.

Vector3D to

End of ray.

IHitInfo hitInfo

Hit info

System.UInt32 raycastCollisionFilter

Collision layer

System.Boolean ignoreConvexShape

Convex radius - allowed to penetrate space, around collision model

Returns
Type Description
System.Boolean

true if hit; false if no hit

CastRayParallel(ref Vector3D, ref Vector3D, List<IHitInfo>, Int32, Action<List<IHitInfo>>)

Cast a ray and returns all matching entities. May be called from parallel thread.

Declaration
void CastRayParallel(ref Vector3D from, ref Vector3D to, List<IHitInfo> toList, int raycastCollisionFilter, Action<List<IHitInfo>> callback)
Parameters
Type Name Description
Vector3D from

Start of ray.

Vector3D to

End of ray.

System.Collections.Generic.List<IHitInfo> toList

List of hits

System.Int32 raycastCollisionFilter

Collision layer

System.Action<System.Collections.Generic.List<IHitInfo>> callback

Callback were results are returned to when query is done

CastRayParallel(ref Vector3D, ref Vector3D, Int32, Action<IHitInfo>)

Cast a ray and return first entity. May be called from parallel thread.

Declaration
void CastRayParallel(ref Vector3D from, ref Vector3D to, int raycastCollisionFilter, Action<IHitInfo> callback)
Parameters
Type Name Description
Vector3D from

Start of ray.

Vector3D to

End of ray.

System.Int32 raycastCollisionFilter

Collision layer

System.Action<IHitInfo> callback

Callback were results are returned to when query is done

CreateBoxPhysics(PhysicsSettings, Vector3, Single)

Creates physical body when DetectorColliderCallback is null, or physics detector, when DetectorColliderCallback is not null. Created physics has a box collision

Declaration
void CreateBoxPhysics(PhysicsSettings settings, Vector3 halfExtends, float convexRadius)
Parameters
Type Name Description
PhysicsSettings settings

Physical settings, created with CreateSettingsForPhysics(IMyEntity, MatrixD, Vector3, Single, Single, UInt16, RigidBodyFlag, Boolean, Nullable<ModAPIMass>) or CreateSettingsForDetector(IMyEntity, Action<IMyEntity, Boolean>, MatrixD, Vector3, RigidBodyFlag, UInt16, Boolean)

Vector3 halfExtends

Half extends of box

System.Single convexRadius

Convex radius in meters

CreateCapsulePhysics(PhysicsSettings, Vector3, Vector3, Single)

Creates physical body when DetectorColliderCallback is null, or physics detector, when DetectorColliderCallback is not null. Created physics has a capsule collision

Declaration
void CreateCapsulePhysics(PhysicsSettings settings, Vector3 vertexA, Vector3 vertexB, float radius)
Parameters
Type Name Description
PhysicsSettings settings

Physical settings, created with CreateSettingsForPhysics(IMyEntity, MatrixD, Vector3, Single, Single, UInt16, RigidBodyFlag, Boolean, Nullable<ModAPIMass>) or CreateSettingsForDetector(IMyEntity, Action<IMyEntity, Boolean>, MatrixD, Vector3, RigidBodyFlag, UInt16, Boolean)

Vector3 vertexA

Local coordinates of capsule's first vertex

Vector3 vertexB

Local coordinates of capsule's second vertex

System.Single radius

Radius of capsule in meters

CreateMassCombined(ICollection<ModAPIMassElement>)

Calculates mass combined from other several masses

Declaration
ModAPIMass CreateMassCombined(ICollection<ModAPIMassElement> massElements)
Parameters
Type Name Description
System.Collections.Generic.ICollection<ModAPIMassElement> massElements

Other masses

Returns
Type Description
ModAPIMass

Combined mass

CreateMassForBox(Vector3, Single)

Creates mass for cube

Declaration
ModAPIMass CreateMassForBox(Vector3 halfExtents, float mass)
Parameters
Type Name Description
Vector3 halfExtents

Cube halfExtents

System.Single mass

Mass in kg

Returns
Type Description
ModAPIMass

Calculated mass properties

CreateMassForCapsule(Vector3, Vector3, Single, Single)

Creates mass for capsule

Declaration
ModAPIMass CreateMassForCapsule(Vector3 startAxis, Vector3 endAxis, float radius, float mass)
Parameters
Type Name Description
Vector3 startAxis

Local coordinates of capsule's first vertex

Vector3 endAxis

Local coordinates of capsule's second vertex

System.Single radius

Radius of capsule in meters

System.Single mass

Mass in kg

Returns
Type Description
ModAPIMass

Calculated mass properties

CreateMassForCylinder(Vector3, Vector3, Single, Single)

Creates mass for cylinder

Declaration
ModAPIMass CreateMassForCylinder(Vector3 startAxis, Vector3 endAxis, float radius, float mass)
Parameters
Type Name Description
Vector3 startAxis

Local coordinates of cylinder's first vertex

Vector3 endAxis

Local coordinates of cylinder's second vertex

System.Single radius

Radius of cylinder in meters

System.Single mass

Mass in kg

Returns
Type Description
ModAPIMass

Calculated mass properties

CreateMassForSphere(Single, Single)

Creates mass for sphere

Declaration
ModAPIMass CreateMassForSphere(float radius, float mass)
Parameters
Type Name Description
System.Single radius

Radius of sphere in meters

System.Single mass

Mass in kg

Returns
Type Description
ModAPIMass

Calculated mass properties

CreateModelPhysics(PhysicsSettings)

Creates physical body when DetectorColliderCallback is null, or physics detector, when DetectorColliderCallback is not null. Created physics has a collision model, taken from entity model

Declaration
void CreateModelPhysics(PhysicsSettings settings)
Parameters
Type Name Description
PhysicsSettings settings

Physical settings, created with CreateSettingsForPhysics(IMyEntity, MatrixD, Vector3, Single, Single, UInt16, RigidBodyFlag, Boolean, Nullable<ModAPIMass>) or CreateSettingsForDetector(IMyEntity, Action<IMyEntity, Boolean>, MatrixD, Vector3, RigidBodyFlag, UInt16, Boolean)

CreateSettingsForDetector(IMyEntity, Action<IMyEntity, Boolean>, MatrixD, Vector3, RigidBodyFlag, UInt16, Boolean)

Used to create physical detectors. They don't have physical collisions, instead they provide trigger callbacks when Entities collide with their shape

Declaration
PhysicsSettings CreateSettingsForDetector(IMyEntity entity, Action<IMyEntity, bool> detectorColliderCallback, MatrixD worldMatrix, Vector3 localCenter, RigidBodyFlag rigidBodyFlags, ushort collisionLayer = 15, bool isPhantom = true)
Parameters
Type Name Description
IMyEntity entity
System.Action<IMyEntity, System.Boolean> detectorColliderCallback
MatrixD worldMatrix
Vector3 localCenter
RigidBodyFlag rigidBodyFlags
System.UInt16 collisionLayer
System.Boolean isPhantom
Returns
Type Description
PhysicsSettings

CreateSettingsForPhysics(IMyEntity, MatrixD, Vector3, Single, Single, UInt16, RigidBodyFlag, Boolean, Nullable<ModAPIMass>)

Used for create physics with collisions

Declaration
PhysicsSettings CreateSettingsForPhysics(IMyEntity entity, MatrixD worldMatrix, Vector3 localCenter, float linearDamping = 0F, float angularDamping = 0F, ushort collisionLayer = 15, RigidBodyFlag rigidBodyFlags, bool isPhantom = false, Nullable<ModAPIMass> mass = null)
Parameters
Type Name Description
IMyEntity entity
MatrixD worldMatrix
Vector3 localCenter
System.Single linearDamping
System.Single angularDamping
System.UInt16 collisionLayer
RigidBodyFlag rigidBodyFlags
System.Boolean isPhantom
System.Nullable<ModAPIMass> mass
Returns
Type Description
PhysicsSettings

CreateSpherePhysics(PhysicsSettings, Single)

Creates physical body when DetectorColliderCallback is null, or physics detector, when DetectorColliderCallback is not null. Created physics has a sphere collision

Declaration
void CreateSpherePhysics(PhysicsSettings settings, float radius)
Parameters
Type Name Description
PhysicsSettings settings

Physical settings, created with CreateSettingsForPhysics(IMyEntity, MatrixD, Vector3, Single, Single, UInt16, RigidBodyFlag, Boolean, Nullable<ModAPIMass>) or CreateSettingsForDetector(IMyEntity, Action<IMyEntity, Boolean>, MatrixD, Vector3, RigidBodyFlag, UInt16, Boolean)

System.Single radius

Radius of sphere

EnsurePhysicsSpace(BoundingBoxD)

Ensure aabb is inside only one subspace. If no, reorder. Must not be called from parallel thread!!!

Declaration
void EnsurePhysicsSpace(BoundingBoxD aabb)
Parameters
Type Name Description
BoundingBoxD aabb

World bounding box

GetCollisionLayer(String)

Given a string, gets the numeric value for the collision layer. Default: 0. TargetDummyLayer = 6 BlockPlacementTestCollisionLayer = 7 MissileLayer = 8 NoVoxelCollisionLayer = 9 LightFloatingObjectCollisionLayer = 10 VoxelLod1CollisionLayer = 11 NotCollideWithStaticLayer = 12 StaticCollisionLayer = 13 CollideWithStaticLayer = 14 DefaultCollisionLayer = 15 DynamicDoubledCollisionLayer = 16 KinematicDoubledCollisionLayer = 17 CharacterCollisionLayer = 18 NoCollisionLayer = 19 DebrisCollisionLayer = 20 GravityPhantomLayer = 21 CharacterNetworkCollisionLayer = 22 FloatingObjectCollisionLayer = 23 ObjectDetectionCollisionLayer = 24 VirtualMassLayer = 25 CollectorCollisionLayer = 26 AmmoLayer = 27 VoxelCollisionLayer = 28 ExplosionRaycastLayer = 29 CollisionLayerWithoutCharacter = 30 RagdollCollisionLayer = 31

Declaration
int GetCollisionLayer(string strLayer)
Parameters
Type Name Description
System.String strLayer

Name of collision layer. See MyPhysics.CollisionLayers for valid names.

Returns
Type Description
System.Int32

Numeric value from MyPhysics.CollisionLayers

Remarks

Default string used if not valid: DefaultCollisionLayer

GetWeaponLeadPrediction(IMyEntity, IMyEntity, MyDefinitionId)

Gets the predicted target coordinates of an entity for weapon leading. Will return Vector3D.Zero if the entity is not valid. If the predicted intercept position cannot be calculated because of missing physics or ammo definitions, then it will return the entity position instead.

Declaration
Vector3D GetWeaponLeadPrediction(IMyEntity shooter, IMyEntity target, MyDefinitionId ammoDefinitionId)
Parameters
Type Name Description
IMyEntity shooter

The entity shooting the target, usually a weapon block or tool

IMyEntity target

The target entity you want to hit

MyDefinitionId ammoDefinitionId

The definition id for the MyAmmoDefinition object the shooter uses.

Returns
Type Description
Vector3D

Vector3D world coordinates of where a fired shot from the weapon should intercept the provided entity target.

☀
☾
In This Article
Back to top
Generated by DocFX
☀
☾