Git Product home page Git Product logo

crispy-physics's Introduction

Crispy Physics

Crispy Physics is a 2D Physics Engine written in C# for Unity3D.

It's a close reapropriation of Box2D assuming a similar structure along with heavily borrowed code.

The main feature of the engine is the ability to step and rollback the simulated world freely along the timeline foreseeing and keeping track of future and past states.

Demo

Features

History and Roll Backs: The engine maitains a history of the simulation so that roll backs to previous ticks are possible. Past states of the entities are also inspectable from the present tick.

Foreseeable Future: The engine presimulates forseeable ticks of the worlds so that each entity can expose its future states.

Crispy Behavior: It is possible to have a body deflected from the simulated curve at a given tick to an authored state, for motived or unmotived reasons. The engine allows this behavior while smoothing the deviation so that it tries to appear physically believable.

Usage

Copy the library folder Librairies/Crispy Physics inside an Unity Project.

Include the Crispy Physics namespace inside your code use the using directive

using CrispyPhysics;

Create the physics World.

IWorld world = WorldFactory.CreateWorld(
    0.01f, // float for the fixed time step in seconds e.g., 0.01f
    gravity // Vector2 for the Physics Gravity e.g., new Vector2(0f, -9.8f);
);

The Crispy Physics engine runs on a fixed time step, it serves as the minimal step for each tick.

Create new bodies inside the world

IBody body = world.CreateBody(
    position, // Vector2 for the current position in units
    angle, // float for the current angle in degrees
    bodyType, // BodyType (Dynamic, Static, Kinematic) representing the nature of the body
    shape // The IShape of the body see ShapeFactory
)

Simulate and step the world

world.Step(
    ticks, // uint for the number of ticks to advance by
    foreseeTicks, // uint for how many future ticks to foresee
    bufferTicks, // uint for how many ticks that have to be predicted by the end of this step
    keepTicks // uint for how many past ticks to remember
);

To rollback to a previous tick

world.RollBack(
    ticks // uint for how many ticks to rollback by
);

An example scene is provided at Examples/A Game of Balls

crispy-physics's People

Contributors

saad-kh avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.