Oasisx Posted February 14, 2020 Share Posted February 14, 2020 Hello, hope you'll are doing fine. I'm a beginner programmer and recently I've been working on a 2d physics game engine in JavaScript. Everything seemed to be working fine until I have come across an annoying bug in my push mechanic. I have created a 2d collision system where object A will be pushed away b object B, etc. In addition, I have created a push mechanic meaning, object A can push object b (if it’s not solid). However, I have come upon a problem where e.g. object A (Player), object B (box which the player can push) and object C (Solid wall), he problem occurs when object a pushes object b against object, what happens is object B gets pushed away by object A, but object A doesn’t get pushed away by B meaning, object A will get inside of object B and it will push the object to the top instead of pushing it to the left by activating the wrong collision detection. (as seen in the video). Video which shows the problem: https://www.youtube.com/watch?v=8DHKJNOrO54 (Project files below) I've been trying to solve this problem for awhile now and I just can't find the perfect solution. If anyone would be able to help it'd be great. Thank you game_v1.zip Quote Link to comment Share on other sites More sharing options...
Milton Posted February 15, 2020 Share Posted February 15, 2020 (edited) Hmm, I think you need to make sure you are always checking from left to right (sort the objects first?). '// Top of other' is triggered because obj1 is actually to the right of obj2. Edited February 15, 2020 by Milton Quote Link to comment Share on other sites More sharing options...
Oasisx Posted February 15, 2020 Author Share Posted February 15, 2020 Thanks for the reply Milton, any idea how I would implement that? Quote Link to comment Share on other sites More sharing options...
Milton Posted February 15, 2020 Share Posted February 15, 2020 Use a temporary obj? If obj1.x > obj2.x create a temp obj. Switch them around. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.