Giter Club home page Giter Club logo

sat-lua's Introduction

SAT-lua

Separating Axis theorem in lua.

It's a simple Lua library for performing collision detection of simple 2D shapes. It uses the Separating Axis Theorem

The aim is to keep it simple as possible, so you don't change the structure of your code and how you store values.

Also it's a first try, contributions are welcome.

It supports detecting collisions between:

  • - Circles - Circles
  • - Circles - Convex polygons
  • - Convex polygons - Convex polygons

If a circle is involved in the collision, it returns the point of collision on the circle.

It's released under the MIT license.

How to use

Get the repo, keep SAT.lua and erase files

function love.load()
SAT  = require("SAT")


end


function love.update()

	-- collider, must be a table with
	-- collider.type = "circle" or "polygon"
	-- collider.vertices -- if it's a polygon
	-- collider.radius -- if it's a circle
	
	-- body must be a table as  like {400,400}
	local shape_a = SAT.new_shape(collider_a, body_a)
	local shape_b = SAT.new_shape(collider_b, body_b)
	
	
	local collide, mtv_axis, overlap = SAT.is_colliding(shape_a, shape_b)
	
	if collide then
	-- shape_a is colliding with b. To stop the colliding, move the shape_a along the mtx_axis.
		local mtv = { mtv_axis[1] * overlap, mtv_axis[2] * overlap]}
		shape_a.position = shape_a.position + mtv -- use a function to add two vectors.
	
	end
end

Update futur

Get the point of collision and faces involded in polygon - polygon collision. I have already something but the code is too dirty and some issues have to fix.

sat-lua's People

Contributors

valentinchcloud avatar

Stargazers

Apikee avatar Jova avatar Michael Wickey avatar

Watchers

James Cloos avatar  avatar

Forkers

enigmanark

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.