Physics Plugin (Simple, 2D and 2kb)

Simple physics for casual games, it’s 2D. It only supports sphere + sphere and sphere + AABB box collisions.

What you can do?

  • Simple games including mobile
  • 2kb super simple engine, loads instantly
  • 2D movement, or simple topdown perspective, isometric movement type of games

Demo project : PlayCanvas 3D HTML5 Game Engine
Test here : Simple Physics (Box + Sphere) - PLAYCANVAS

Tutorial and Github
Repo : GitHub - devcem/playcanvas-physics: Simple physics for casual games
Video : https://www.youtube.com/watch?v=0oDCl_D34X8&ab_channel=CemDemir

7 Likes

Thank you for sharing!

A couple of suggestions that would help improving it:

  • Consider using line-circle intersection to allow multiple contacts per move step. You could then find the average direction normal to reverse the movement to. This will prevent clipping into walls when touching corners. I had an example that shows it:
    PlayCanvas 3D HTML5 Game Engine
  • Try not to use vector math in the transform chains, like .getPosition().sub(...). This will modify the internal vector of the entity, that stores the transform. It will often introduce visual bugs like erratic movement. A better way would be to copy it to some temp vector and modify that instead.
2 Likes

Thanks for sharing your tools with the community, Cem! It’s a really cool thing to do.

what does this error mean?

[playcanvas-1.65.5.dbg.js:5015]: Cannot read properties of undefined (reading ‘x’)

TypeError: Cannot read properties of undefined (reading ‘x’)
at Vec3.sub (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:5015:20)
at object.entity.revertTranslate (https://launch.playcanvas.com/api/assets/files/Scripts/Game%20Mechs/Physics.js?id=154191269&branchId=52a6bed9-6a5d-430e-b24e-b4ab9b50cdc0:35:53)
at Physics.calculateBoxCollision (https://launch.playcanvas.com/api/assets/files/Scripts/Game%20Mechs/Physics.js?id=154191269&branchId=52a6bed9-6a5d-430e-b24e-b4ab9b50cdc0:131:29)
at Physics.checkCollisions (https://launch.playcanvas.com/api/assets/files/Scripts/Game%20Mechs/Physics.js?id=154191269&branchId=52a6bed9-6a5d-430e-b24e-b4ab9b50cdc0:85:26)
at Physics.update (https://launch.playcanvas.com/api/assets/files/Scripts/Game%20Mechs/Physics.js?id=154191269&branchId=52a6bed9-6a5d-430e-b24e-b4ab9b50cdc0:138:10)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:97474:22)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:97508:15)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:98154:52)
at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:98172:11)
at ComponentSystemRegistry.fire (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:1466:21)

[playcanvas-1.65.5.dbg.js:88835]: Cannot read properties of undefined (reading ‘setValue’)

TypeError: Cannot read properties of undefined (reading ‘setValue’)
at RigidBodyComponentSystem.raycastFirst (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:88835:19)
at JumpBalloon.doRaycast (https://launch.playcanvas.com/api/assets/files/Scripts/Movement/jump-balloon.js?id=154082898&branchId=52a6bed9-6a5d-430e-b24e-b4ab9b50cdc0:54:45)
at JumpBalloon.update (https://launch.playcanvas.com/api/assets/files/Scripts/Movement/jump-balloon.js?id=154082898&branchId=52a6bed9-6a5d-430e-b24e-b4ab9b50cdc0:20:10)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:97474:22)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:97508:15)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:98154:52)
at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:98172:11)
at ComponentSystemRegistry.fire (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:1466:21)
at AppBase.update (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:65240:19)
at AppBase.tick (https://code.playcanvas.com/playcanvas-1.65.5.dbg.js:66288:20)