Skip to content

Latest commit

 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pulse

简体中文

Pulse is a small experimental 2D physics engine for C# and Unity projects that need simple custom collision behavior rather than a full realistic simulation.

Pulse cover

What Pulse does

  • Creates box and circle rigid bodies with position, velocity, mass, layer, trigger, and restitution data.
  • Applies gravity and translational movement through an explicit fixed-step tick.
  • Detects and resolves the implemented box and circle collision pairs.
  • Reports collision and trigger enter, stay, and exit events.
  • Keeps physics state independent from Unity Rigidbody2D and Collider2D components.

Installation

Pulse depends on Abacus. Add Abacus first:

https://github.com/onovich/Abacus.git?path=/Assets/com.mortise.abacus#main

Then add Pulse through Window → Package Manager → Add package from git URL:

https://github.com/onovich/Pulse.git?path=/Assets/com.mortise.pulse#main

The package metadata declares Unity 2019.4 or later. The included project uses Unity 2022.3.13f1c1.

Quick start

using MortiseFrame.Abacus;
using MortiseFrame.Pulse;
using UnityEngine;

public sealed class PhysicsSample : MonoBehaviour {
    PhysicalCore physicsCore;

    void Start() {
        physicsCore = new PhysicalCore();
        physicsCore.SetGravity(new FVector2(0, -9.8f));

        var floor = physicsCore.Rigidbody_CreateBox(
            new FVector2(0, -2),
            new FVector2(8, 1)
        );
        floor.SetIsStatic(true);

        var box = physicsCore.Rigidbody_CreateBox(
            new FVector2(0, 2),
            FVector2.one
        );
        box.SetMass(1);
        box.SetRestitution(0.6f);

        physicsCore.EventCenter.OnCollisionEnterHandle = (a, b) => {
            Debug.Log($"Collision: {a.ID} / {b.ID}");
        };
    }

    void FixedUpdate() {
        physicsCore.Tick(Time.fixedDeltaTime);
    }

    void OnDestroy() {
        physicsCore?.Clear();
    }
}

Status

Pulse is an unfinished learning and prototyping library. Basic translation, gravity, narrow-phase collision, response, and events are present. Rotation dynamics, broad-phase acceleration, continuous collision detection, and several OBB collision-resolution paths are missing.

The current package version is 0.0.2. It has not been validated in a commercial project and should not replace Unity Physics 2D in production without substantial project-specific testing.

Development

Runtime code lives in Assets/com.mortise.pulse/Scripts_Runtime/. The project was inspired by FPPhysics2d.

License

MIT

About

An experimental 2D physics engine for C# and Unity.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages