I’ve finally gotten my character to jump for my platform game, but now I’m stuck having to stop him from walking through walls. I’ve tried many different ways of doing this, such as:
for (var s:Number = 2; s < _parent.collision_detection_presision; s++) {
//note: _parent.collision_detection_precision = 6
//check multiple sides of player to see if they're touching any walls
if (_parent[_parent.groundArray*].hitTest(this._x - (this[_parent.hitBox]._width / 2), this._y - (this[_parent.hitBox]._height / s), true)) {
//if the ground is touching the left side of the player
this._x = this._x - xSpeed; //push player left
} else if (_parent[_parent.groundArray*].hitTest(this._x + (this[_parent.hitBox]._width / 2), this._y - (this[_parent.hitBox]._height / s), true)) {
//if the ground is touching the right side of the player
this._x = this._x + xSpeed; //push player right
}
}
I’ve also tried different methods similar to that, but not using a for… loop, just checking different parts of the player (ie. feet, head, body) to see if they’re touching the wall. None seem to work. Anyone wanna help me in figuring this out?
If you need to see the source code, feel free to ask
Cheers,
-Mike