threE deE

10-06-2003, 12:09 AM

I have this code (with some help from the Maze.fla sample).

This code has been applied to the "wall" mc that moves and detects the player's mc. This works but the detection for angled edges on the walls is a bit dodgy and it moves the player back to far from the wall which makes the movement skippy. how would i fix the hittest code to get smooth close collision detection for a topdown view run around game??

onClipEvent(enterFrame){

with (_root.player){

angle = 5

spd = 1.5

// Move Forward

if (Key.isDown(Key.UP)){

_x += spd*Math.sin(_rotation*(Math.PI/180))

_y -= spd*Math.cos(_rotation*(Math.PI/180))

}

// Move Backward

if (Key.isDown(Key.DOWN)){

_x -= spd/2*Math.sin(_rotation*(Math.PI/180))

_y += spd/2*Math.cos(_rotation*(Math.PI/180))

}

// Turn Left

if (Key.isDown(Key.LEFT)){

_rotation -= angle

}

// Turn Right

if (Key.isDown(Key.RIGHT)){

_rotation += angle

}

if (wallz.hitTest(getBounds(_root).xMax, _y, true)) {

_x -= spd

}

if (wallz.hitTest(getBounds(_root).xMin, _y, true)) {

_x += spd

}

if (wallz.hitTest(_x, getBounds(_root).yMax, true)) {

_y -= spd

}

if (wallz.hitTest(_x, getBounds(_root).yMin, true)) {

_y += spd

}

}

}

This code has been applied to the "wall" mc that moves and detects the player's mc. This works but the detection for angled edges on the walls is a bit dodgy and it moves the player back to far from the wall which makes the movement skippy. how would i fix the hittest code to get smooth close collision detection for a topdown view run around game??

onClipEvent(enterFrame){

with (_root.player){

angle = 5

spd = 1.5

// Move Forward

if (Key.isDown(Key.UP)){

_x += spd*Math.sin(_rotation*(Math.PI/180))

_y -= spd*Math.cos(_rotation*(Math.PI/180))

}

// Move Backward

if (Key.isDown(Key.DOWN)){

_x -= spd/2*Math.sin(_rotation*(Math.PI/180))

_y += spd/2*Math.cos(_rotation*(Math.PI/180))

}

// Turn Left

if (Key.isDown(Key.LEFT)){

_rotation -= angle

}

// Turn Right

if (Key.isDown(Key.RIGHT)){

_rotation += angle

}

if (wallz.hitTest(getBounds(_root).xMax, _y, true)) {

_x -= spd

}

if (wallz.hitTest(getBounds(_root).xMin, _y, true)) {

_x += spd

}

if (wallz.hitTest(_x, getBounds(_root).yMax, true)) {

_y -= spd

}

if (wallz.hitTest(_x, getBounds(_root).yMin, true)) {

_y += spd

}

}

}