Im testing on a simple game and i was starting to get into collision between the character and any object. I first went about this by getting the characters last position and changing the characters coordinates to it. I was wondering if there would be anyother way of doing it? Right now i have the "detection" part out of the way.
//Class Function
iscolliding(object) {
if (this.x < object.x + object.width &&
this.x + this.width > object.x &&
this.y < object.y + object.height &&
this.height + this.y > object.y) {
return true;
} else {
return false;
}
}
//------------------------------------------------------------------
//Is colliding function (returns bool)
if (character.iscolliding(/*Object*/)) {
console.log('working');
}
Where there is console.log('working')
i was wondering what i would do next? How would i stop the character from going through the object
? I would prefer not to use Jquery, just plain javascript>
Thanks (:
If you need any more info i would gladly answer any comments below! (: