I am currently playing with crafty js and have created 2D top-down world with solid objects.
When a collision event occurs with any solid object, I want my player to no longer be able to move in the direction of said object (as there is a solid object blocking its path).
I have found a few tutorials online which cover this topic, however the methods and functions they are calling are depricated.
.onHit("solid", function(from) {
console.log("ouch");
}
I can register the collision when my player hits a solid, but I do not know how to stop the movement.
I know that I can setup specific solutions per collision (for example, a top border can update y to move off the specific top collision), however I want a generic approach so colliding with any solid results in my character not being able to move.
When I try to call from.x
I receive that the element is undefined
, while other elements such as from.length
do work, which does not make sense to me.
Or offer some demo-code which is compatible with the latesty crafty?