Skip to content

Commit

Permalink
Merge pull request #45 from InvalidArgument3/cores
Browse files Browse the repository at this point in the history
convert to capsule physics
  • Loading branch information
InvalidArgument3 authored Jun 11, 2024
2 parents f7e1d10 + d7ee7d0 commit bbadca7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,33 @@ private int GetRandomDropAmount(AsteroidType type)

public void OnDestroy()
{
SplitAsteroid();
try
{
SplitAsteroid();
}
catch (Exception ex)
{
Log.Exception(ex, typeof(AsteroidEntity), "Exception in OnDestroy:");
throw; // Rethrow the exception for the debugger
}
}

public bool DoDamage(float damage, MyStringHash damageSource, bool sync, MyHitInfo? hitInfo = null, long attackerId = 0, long realHitEntityId = 0, bool shouldDetonateAmmo = true, MyStringHash? extraInfo = null)
{
_integrity -= damage;
Log.Info($"DoDamage called with damage: {damage}, damageSource: {damageSource.String}, attackerId: {attackerId}, realHitEntityId: {realHitEntityId}, new integrity: {_integrity}");

if (hitInfo.HasValue)
{
var hit = hitInfo.Value;
Log.Info($"HitInfo - Position: {hit.Position}, Normal: {hit.Normal}, Velocity: {hit.Velocity}");
}

if (Integrity < 0)
{
Log.Info("Integrity below 0, calling OnDestroy");
OnDestroy();
}
return true;
}

Expand Down Expand Up @@ -292,22 +311,26 @@ private void Init(Vector3D position, float size, Vector3D initialVelocity, Aster
private void CreatePhysics()
{
float mass = 10000 * Size * Size * Size;
float radius = Size / 2; // Assuming Size represents the diameter

PhysicsSettings settings = MyAPIGateway.Physics.CreateSettingsForPhysics(
this,
WorldMatrix,
Vector3.Zero,
linearDamping: 0f, // Remove damping
angularDamping: 0f, // Remove damping
collisionLayer: CollisionLayers.DefaultCollisionLayer,
rigidBodyFlags: RigidBodyFlag.RBF_DEFAULT,
collisionLayer: CollisionLayers.NoVoxelCollisionLayer,
isPhantom: false,
mass: new ModAPIMass(PositionComp.LocalAABB.Volume(), mass, Vector3.Zero, mass * PositionComp.LocalAABB.Height * PositionComp.LocalAABB.Height / 6 * Matrix.Identity)
);

MyAPIGateway.Physics.CreateBoxPhysics(settings, PositionComp.LocalAABB.HalfExtents, 0);
MyAPIGateway.Physics.CreateSpherePhysics(settings, radius);
Physics.Enabled = true;
Physics.Activate();
}


private Vector3D RandVector()
{
var theta = MainSession.I.Rand.NextDouble() * 2.0 * Math.PI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRageMath;
using ProtoBuf;

namespace DynamicAsteroids.AsteroidEntities
{
internal class AsteroidSpawner
{
public List<AsteroidEntity> _asteroids;
private const double MinDistanceFromVanillaAsteroids = 1000; // 1 km
private const double MinDistanceFromPlayer = 3000; // Minimum distance from the player to spawn new asteroids
private bool _canSpawnAsteroids = false;
private DateTime _worldLoadTime;

Expand Down Expand Up @@ -84,7 +84,12 @@ public void UpdateTick()
int asteroidsSpawned = 0;
while (_asteroids.Count < AsteroidSettings.MaxAsteroidCount && asteroidsSpawned < 10)
{
Vector3D newPosition = playerPosition + RandVector() * AsteroidSettings.AsteroidSpawnRadius;
Vector3D newPosition;
do
{
newPosition = playerPosition + RandVector() * AsteroidSettings.AsteroidSpawnRadius;
} while (Vector3D.DistanceSquared(newPosition, playerPosition) < MinDistanceFromPlayer * MinDistanceFromPlayer);

Vector3D newVelocity;
if (!AsteroidSettings.CanSpawnAsteroidAtPoint(newPosition, out newVelocity))
continue;
Expand Down
9 changes: 7 additions & 2 deletions Dynamic Asteroids/Data/newfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,14 @@ using SC.SUGMA;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRageMath;
using ProtoBuf;

namespace DynamicAsteroids.AsteroidEntities
{
internal class AsteroidSpawner
{
public List<AsteroidEntity> _asteroids;
private const double MinDistanceFromVanillaAsteroids = 1000; // 1 km
private const double MinDistanceFromPlayer = 3000; // Minimum distance from the player to spawn new asteroids
private bool _canSpawnAsteroids = false;
private DateTime _worldLoadTime;

Expand Down Expand Up @@ -860,7 +860,12 @@ namespace DynamicAsteroids.AsteroidEntities
int asteroidsSpawned = 0;
while (_asteroids.Count < AsteroidSettings.MaxAsteroidCount && asteroidsSpawned < 10)
{
Vector3D newPosition = playerPosition + RandVector() * AsteroidSettings.AsteroidSpawnRadius;
Vector3D newPosition;
do
{
newPosition = playerPosition + RandVector() * AsteroidSettings.AsteroidSpawnRadius;
} while (Vector3D.DistanceSquared(newPosition, playerPosition) < MinDistanceFromPlayer * MinDistanceFromPlayer);

Vector3D newVelocity;
if (!AsteroidSettings.CanSpawnAsteroidAtPoint(newPosition, out newVelocity))
continue;
Expand Down

0 comments on commit bbadca7

Please sign in to comment.